Matplotlib install on Windows

运行环境:Python3

>>pip install matplotlib
  • 安装成功后

开始我们的第一个例子:stacked bar graph

  • 结果展示:

    bar stack.png

  • Code:

>>import numpy as np
>>import matplotlib.pyplot as plt  #导入库
N = 5
menMeans = (20, 35, 30, 35, 27)  #均值
womenMeans = (25, 32, 34, 20, 25)
menStd = (2, 3, 4, 1, 2)  #标准差
womenStd = (3, 5, 2, 3, 3)
ind = np.arange(N)  # 定义(5)个组
width = 0.35      
p1 = plt.bar(ind, menMeans, width, yerr=menStd)  #plt.bar(x,y.width,yerr = std)
p2 = plt.bar(ind, womenMeans, width, 
                bottom=menMeans, yerr=womenStd)
plt.ylabel('Scores') 
plt.title('Scores by group and gender') 
plt.xticks(ind, ('G1', 'G2', 'G3', 'G4', 'G5')) 
plt.yticks(np.arange(0, 81, 10))
plt.legend((p1[0], p2[0]), ('Men', 'Women'))
plt.savefig('bar stack.png')
plt.show()

参考链接:https://matplotlib.org/

https://www.jianshu.com/p/31881fbbac7a

「点点赞赏,手留余香」

    还没有人赞赏,快来当第一个赞赏的人吧!
0 条回复 A 作者 M 管理员
    所有的伟大,都源于一个勇敢的开始!
欢迎您,新朋友,感谢参与互动!欢迎您 {{author}},您在本站有{{commentsCount}}条评论