条形图

import matplotlib.pyplot as plt
import numpy as np
plt.style.use('ggplot')        #ggplot R的画图工具包

 #创建条形图的数据,横轴刻度需要索引位置和标签

customers=['A','B','C','D','E']
customers_index=range(len(customers))
sale_amounts=[122,78,56,90,45]

#在figure窗口创建一行一列切一个subplot子图

fig=plt.figure(1,figsize=(8,6),dpi=200,facecolor="None",edgecolor="None",frameon=True)
ax=fig.add_subplot(1,1,1)

#创建条形图,customers_index指定条形图左侧x的坐标,sale_amounts指定了条形图的高度,align指定条形图位于标签的中间位置

ax.bar(customers_index,sale_amounts,align='center',color="darkblue")
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')

#将刻度标签从customers变为customers,rotation=0指定刻度标签是水平的,而不是倾斜的
plt.xticks(customers_index,customers,rotation=0,fontsize="small")
plt.xlabel('customer name',color="black",fontsize=8)
plt.ylabel('sale amount')
plt.title('Sale amount per customer')
plt.savefig('E:\python\慕课网 python\.idea\photo\Bar_plot.png',dpi=400,bbox_inches='tight')
plt.show()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值