01
季度销量双子图
用 subplot 上下排列两组数据,分别展示柱状图与折线图。
查看 Python 代码 +
%matplotlib auto
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ["SimHei"]
x_quarter = ['第一季度','第二季度','第三季度','第四季度']
y_watch = np.array([120, 150, 130, 180])
y_headset = np.array([200, 180, 220, 250])
ax1 = plt.subplot(211)
bar_width = 0.3
ax1.bar(x_quarter,y_watch,width = bar_width)
ax1.set_title("智能手表季度销量", fontsize=11)
ax1.set_ylabel('销量(万台)')
ax2 = plt.subplot(212)
ax2.plot(x_quarter,y_headset)
ax2.set_title("蓝牙耳机季度销量", fontsize=11)
ax2.set_xlabel('季度')
ax2.set_ylabel('销量(万台)')
plt.tight_layout()
plt.show()
