python绘制饼图程序,如何使用python创建简单的饼图

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?

解决方案

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:

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值