# #多个图形的合并
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
import numpy as np
plt.rcParams['font.sans-serif']=['Microsoft Yahei']
plt.rcParams['axes.unicode_minus']=False
trade=pd.read_excel(r'E:\Python学习\Prod_Trade.xlsx')
trade['year']=trade.Date.dt.year
trade['month']=trade.Date.dt.month
plt.figure(figsize=(12,6))
ax1=plt.subplot2grid(shape=(2,3),loc=(0,0))
order_count=trade.Order_Class.value_counts()
ax1.set_aspect(aspect='equal')
ax1.pie(x=order_count,labels=trade.Order_Class.unique(),autopct='%.1f%%')
ax1.set_title("各等级的订单比例")
ax2=plt.subplot2grid(shape=(2,3),loc=(0,1))
two=trade[trade.year==2012].groupby(by='month').aggregate({'Sales':np.sum})
two.plot(title='2012年各月份销售走势',ax=ax2,legend=False)
ax2.set_xlabel('')
ax3=plt.subplot2grid(shape=(2,3),rowspan=2,loc=(0,2))
sns.boxplot(x='Transport',y='Trans_Cost',data=trade,ax=ax3)
ax3.set_xlabel("")
ax3.set_ylabel("运输成本")
ax3.set_title("各运输方式成本的分布")
ax4=plt.subplot2grid(shape=(2,3),loc=(1,0),colspan=2)
sns.distplot(trade.Sales[trade.year==2012],bins=40,norm_hist=True,
ax=ax4,kde_kws={'linestyle':'--','color':'red'})
ax4.set_xlabel("销售额")
ax4.set_title('2012年客单价分布图')
plt.subplots_adjust(hspace=0.6,wspace=0.3)
plt.show()
image.png
网友评论