时间:2021-07-01 10:21:17 帮助过:15人阅读
实例代码如下:
1. 柱状图
- import matplotlib.pyplot as plt
- plt.bar(left = 0,height = 1)
- plt.show()
运行效果如下:
2. 饼形图
- #! coding: cp936
- from pylab import *
- # make a square figure and axes
- figure(1, figsize=(6,6))
- ax = axes([0.1, 0.1, 0.8, 0.8])
- fracs = [45, 30, 25] #每一块占得比例,总和为100
- explode=(0, 0, 0.08) #离开整体的距离,看效果
- labels = 'Hogs', 'Dogs', 'Logs' #对应每一块的标志
- pie(fracs, explode=explode, labels=labels,
- autopct='%1.1f%%', shadow=True, startangle=90, colors = ("g", "r", "y"))
- # startangle是开始的角度,默认为0,从这里开始按逆时针方向依次展开
- title('Raining Hogs and Dogs') #标题
- show()
运行效果如下: