柱状图和条形图

柱状图和条形图


import matplotlib.pyplot as plt
import numpy as np
import matplotlib.ticker as mtick  
from matplotlib.font_manager import FontProperties
font = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=14)
a=y_axis_1 #数据
b=y_axis_2
x=[i for i in range(5)]

plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
# yticks = mtick.FormatStrFormatter()  #设置百分比形式的坐标轴
lx=[u'7月',u'8月',u'9月',u'10月',u'11月']

fig = plt.figure()  
ax1 = fig.add_subplot(111)  
ax1.set_ylim([0, 8000])
ax1.bar(l,a,alpha=0.3,color='blue',label=u'认购金额')
plt.ylabel('count',fontsize=15)

for i,(_x,_y) in enumerate(zip(l,a)):  
    plt.text(_x,_y,b[i],color='black',fontsize=10)  #将数值显示在图形上
ax1.legend()

plt.legend(prop={'family':'SimHei','size':8})  #设置中文

ax2 = ax1.twinx() # this is the important function  
  
ax2.legend(loc=2)
ax2.set_ylim([0, 1300])  #设置y轴取值范围
ax2.plot(x, b,'or-',label=u'认购数量');
plt.ylabel('number',fontsize=15)

plt.legend(prop={'family':'SimHei','size':8},loc="upper left") 
plt.xticks(l,lx)
plt.xlabel('month',fontsize=10)
plt.title('2019年7-11月认购金额和认购数量',fontsize=15)
plt.show()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值