码迷,mamicode.com
首页 > 其他好文 > 详细

柱状图

时间:2018-01-20 22:45:09      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:style   src   log   label   ipy   bottom   命令   insert   令行   

问题1:
for m, n in zip(x1, y1):
plt.text(m + 0.08, n + 20, ‘%.2f‘ % n, ha=‘center‘, va=‘bottom‘)

for m, n in zip(x2, y2):
plt.text(m - 0.08, n + 10, ‘%.2f‘ % n, ha=‘center‘, va=‘bottom‘)
问题2:
如果是三个图怎么办

0.5:柱状图的宽度
align:对齐方式
x1=[1,2,3]
x2=[1,2,3]
y1=[600,700,800]
y2=[500,900,1000]

plt.figure()
plt.bar(x1,y1,0.1,color=‘y‘,align=‘edge‘,label=‘进口 单位/美元‘)
plt.bar(x2,y2,-0.1,color=‘r‘,align=‘edge‘,label=‘出口 单位/美元‘)

for m, n in zip(x1, y1):
    plt.text(m + 0.08, n + 20, ‘%.2f‘ % n, ha=‘center‘, va=‘bottom‘)

for m, n in zip(x2, y2):
    plt.text(m - 0.08, n + 10, ‘%.2f‘ % n, ha=‘center‘, va=‘bottom‘)

plt.xlabel(‘第一季度/月‘)
plt.ylabel(‘进出口额/美元‘)
plt.title(‘第一季度进出口数据‘)
plt.xticks(range(1,4),[str(i)+‘月‘ for i in range(1,4)])
plt.legend()
plt.show()

技术分享图片

 

 

 

adding

1.按到Insert会出现想命令行一样的输入形式

2.打开ipynb文件,将文件移到jupyter下就可以打开了

柱状图

标签:style   src   log   label   ipy   bottom   命令   insert   令行   

原文地址:https://www.cnblogs.com/jad-xxd/p/8322023.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!