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()
条形图
最新推荐文章于 2023-12-10 09:34:27 发布