How to create a simple pie chart using python

后端 未结 1 895
感动是毒
感动是毒 2021-01-21 05:29

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

1条回答
  •  隐瞒了意图╮
    2021-01-21 05:56

    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()
    

    0 讨论(0)
提交回复
热议问题