代码如下
import matplotlib.pyplot as pltimport numpy as npx = np.arange(0,10,0.1)y1 = 0.05 * x**2y2 = -1 * y1fig, ax1 = plt.subplots()ax2 = ax1.twinx()ax1.plot(x,y1,'g-')ax2.plot(x,y2,'b-')ax1.set_xlabel("X data")ax1.set_ylabel("Y1",color='g')ax2.set_ylabel("Y2",color='b')plt.show()
如果觉得《Python:(使用matplotlib画图)次坐标轴 两个坐标轴》对你有帮助,请点赞、收藏,并留下你的观点哦!