Python matplotlib 绘制双Y轴曲线图的示例代码
Matplotlib简介
Matplotlib是非常强大的python画图工具
Matplotlib可以画图线图、散点图、等高线图、条形图、柱形图、3D图形、图形动画等。
Matplotlib安装
pip3 install matplotlib#python3
双X轴的
可以理解为共享y轴
ax1=ax.twiny()
ax1=plt.twiny()
双Y轴的
可以理解为共享x轴
ax1=ax.twinx()
ax1=plt.twinx()
自动生成一个例子
x = np.arange(0., np.e, 0.01)
y1 = np.exp(-x)
y2 = np.log(x)
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.plot(x, y1)
ax1.set_ylabel("Y values for exp(-x)")
ax1.set_title("Double Y axis")
ax2 = ax1.twinx() # this is the important function
ax2.plot(x, y2, "r")
ax2.set_xlim([0, np.e])
ax2.set_ylabel("Y values for ln(x)")
ax2.set_xlabel("Same X for both exp(-x) and ln(x)")<