matplotlib-次坐标轴 发表于 2019-06-11 | 分类于 python 详情请看莫烦老师教程莫烦python 代码123456789101112131415161718import matplotlib.pyplot as pltimport numpy as npx = np.arange(0, 10, 0.1)y1 = 0.05 * x**2y2 = -2 *y1fig, ax1 = plt.subplots()ax2 = ax1.twinx() # mirror the ax1ax1.plot(x, y1, 'g-')ax2.plot(x, y2, 'b-')ax1.set_xlabel('X data')ax1.set_ylabel('Y1 data', color='g')ax2.set_ylabel('Y2 data', color='b')plt.show() 结果