matplotlib的基本用法(十五)——主次坐标轴

xiaoxiao2021-02-28  129

文章作者:Tyan 博客:noahsnail.com  |   |  简书

本文主要介绍matplotlib的一些用法。

Demo import numpy as np import matplotlib.pyplot as plt # 定义数据 x = np.arange(0, 10, 0.1) y1 = 0.05 * x ** 2 y2 = -1 * y1 # 定义figure fig, ax1 = plt.subplots() # 得到ax1的对称轴ax2 ax2 = ax1.twinx() # 绘制图像 ax1.plot(x, y1, 'g-') ax2.plot(x, y2, 'b--') # 设置label ax1.set_xlabel('X data') ax1.set_ylabel('Y 1', color = 'g') ax2.set_ylabel('Y 2', color = 'b') plt.show() 结果

参考资料

https://www.youtube.com/user/MorvanZhou
转载请注明原文地址: https://www.6miu.com/read-38745.html

最新回复(0)