如何使用python创建简单的饼图 [英] How to create a simple pie chart using python

查看:210
本文介绍了如何使用python创建简单的饼图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试仅使用两个变量就使用python生成一个简单的饼图.表示百分比.安装matplotlib软件包时总是遇到错误"vcvarsall.bat" not found.为此是否不可避免地安装Visual Studio?

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?

推荐答案

安装matplotlib不需要Visual Studio.为了获得最佳结果,请首先从python.org安装32位或64位Python,具体取决于计算机的体系结构和运行的Windows版本(例如,即使您使用的是64位处理器,如果您正在运行32位Windows,请下载32位Python).该版本并不重要,我更喜欢3.3.3,但是更多的软件包与2.7.6兼容,所以请选择. Matplotlib及其依赖项对于这两个版本均可用.

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.

接下来,转到Christoph Gohlke的适用于Windows的Python扩展程序包,并下载适用于您的版本的以下程序包Python版本:

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

这些软件包都是自解压安装程序.以任何顺序运行它们,完成后,您应该就可以导入并使用matplotlib了.

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.

示例饼图程序,来自此处:

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

这篇关于如何使用python创建简单的饼图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆