import pandas as pd import numpy as np import matplotlib.pyplot as plt import seaborn as sns import matplotlib as mpl name_new_list = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'] num_sale_list = [369,324,400,388,260,81,27,22,0,0,0,113] x = [c + 0.5 for c in range(len(name_new_list))] sum_ = sum(num_sale_list) num_list_new = [x/sum_*100 for x in num_sale_list] plt.rcParams['figure.figsize'] = (12.0, 12.0) plt.subplot(211) sns.barplot(x=name_new_list, y=num_sale_list,color='lightskyblue',label=u'销量') plt.legend(loc=2) plt.title ('月销量分布情况') plt.ylim(0,max(num_sale_list)*1.2) plt.ylabel(u'销量') plt.subplot(212) plt.plot(x, num_list_new, marker='o', mec='r', mfc='w',color='r',label=u'销量占比') for xy in zip(x,num_list_new): plt.annotate(str('%.0f'%xy[1])+'%', xy=xy, xytext=(0,0), textcoords = 'offset points',color='r') plt.xticks(x,name_new_list) plt.legend(loc=1) plt.ylabel(u'销量占比') plt.ylim(0, max(num_list_new)*1.2) plt.title ( '月销量占比分布情况')
import pandas as pd import numpy as np import matplotlib.pyplot as plt import seaborn as sns import matplotlib as mpl name_new_list = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'] num_sale_list = [369,324,400,388,260,81,27,22,0,0,0,113] x = [c + 0.5 for c in range(len(name_new_list))] sum_ = sum(num_sale_list) num_list_new = [x/sum_*100 for x in num_sale_list] plt.rcParams['figure.figsize'] = (12.0, 12.0) plt.subplot(211) sns.barplot(x=name_new_list, y=num_sale_list,color='lightskyblue',label=u'销量') plt.legend(loc=2) plt.title ('月销量分布情况') plt.ylim(0,max(num_sale_list)*1.2) plt.ylabel(u'销量') plt.subplot(212) plt.plot(x, num_list_new, marker='o', mec='r', mfc='w',color='r',label=u'销量占比') for xy in zip(x,num_list_new): plt.annotate(str('%.0f'%xy[1])+'%', xy=xy, xytext=(0,0), textcoords = 'offset points',color='r') plt.xticks(x,name_new_list) plt.legend(loc=1) plt.ylabel(u'销量占比') plt.ylim(0, max(num_list_new)*1.2) plt.title ( '月销量占比分布情况')