plt.title("销售趋势图", fontdict={'family':'Microsoft YaHei', 'color': 'k', 'size': 15}, loc='left')
plt.xlabel("月份", fontdict={'family':'Microsoft YaHei', 'color': 'k', 'size': 12}, labelpad=10)
plt.ylabel("销售额(万元)", fontdict={'family':'Microsoft YaHei', 'color': 'k', 'size': 12}, labelpad=10)
plt.ylim(50, 300)
plt.xlim(100,300)
plt.legend(loc='best', fontsize=12) # best:matplotlib根据图表自动选择最优位置
x = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
y1 = [123, 145, 152, 182, 147, 138, 189, 201, 203, 211, 201, 182]
y2 = [102, 121, 138, 154, 171, 178, 199, 231, 228, 202, 231, 271]
for a, b, c in zip(x, y1, y2):
plt.text(a, b, b, va='bottom', fontdict={"size":14})
plt.text(a, c, c, va='top', fontdict={"size":14})
参数b为True时展示网格线,axis支持x、y、both三个值,分别表示展示纵向网格线,横向网格线和纵向横向都展示;
plt.grid(b=True, axis='y', linestyle='--', linewidth=1, color='grey')
要在画布之前设置
[‘Solarize_Light2’, ‘_classic_test_patch’, ‘bmh’, ‘classic’, ‘dark_background’, ‘fast’, ‘fivethirtyeight’, ‘ggplot’, ‘grayscale’, ‘seaborn’, ‘seaborn-bright’, ‘seaborn-colorblind’, ‘seaborn-dark’, ‘seaborn-dark-palette’, ‘seaborn-darkgrid’, ‘seaborn-deep’, ‘seaborn-muted’, ‘seaborn-notebook’, ‘seaborn-paper’, ‘seaborn-pastel’, ‘seaborn-poster’, ‘seaborn-talk’, ‘seaborn-ticks’, ‘seaborn-white’, ‘seaborn-whitegrid’, ‘tableau-colorblind10’]
plt.style.use(['ggplot'])