How to create a simple pie chart using python

假如想象 提交于 2019-12-02 02:10:42

问题


Ive been trying to generate a simple pie chart using python just using two variables. representing percentages.I always encounter an error "vcvarsall.bat" not found upon installing matplotlib package.Is it inevitable installing visual studio for this?


回答1:


Visual Studio is not required to install matplotlib. For best results, first install Python from python.org, either 32- or 64-bit, depending on your computer's architecture and the version of Windows you're running (for example, even if you have a 64-bit processor, if you're running 32-bit Windows, download 32-bit Python). The version doesn't especially matter, I prefer 3.3.3, but more packages are compatible with 2.7.6, so take your pick. Matplotlib and its dependencies are all available for either version.

Next, go to Christoph Gohlke's Python Extension Packages for Windows and download the following packages for your version of Python:

  • matplotlib
  • numpy
  • python-dateutil
  • pytz
  • pyparsing
  • six
  • Pillow
  • tornado
  • pyside
  • pyqt

The packages are all self-extracting installers. Run them in any order, and when you're done you should be able to import and use matplotlib just fine.

An example pie chart program, from here:

from pylab import *

# make a square figure and axes
figure(1, figsize=(6,6))
ax = axes([0.1, 0.1, 0.8, 0.8])

# The slices will be ordered and plotted counter-clockwise.
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
fracs = [15, 30, 45, 10]
explode=(0, 0.05, 0, 0)

pie(fracs, explode=explode, labels=labels,
                autopct='%1.1f%%', shadow=True, startangle=90)
                # The default startangle is 0, which would start
                # the Frogs slice on the x-axis.  With startangle=90,
                # everything is rotated counter-clockwise by 90 degrees,
                # so the plotting starts on the positive y-axis.

title('Raining Hogs and Dogs', bbox={'facecolor':'0.8', 'pad':5})

show()


来源:https://stackoverflow.com/questions/20714966/how-to-create-a-simple-pie-chart-using-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!