python第二阶段(24)numpy入门基础-可视化之双坐标轴

    科技2025-10-25  11

    numpy入门基础-可视化之双坐标轴

    1、添加双坐标轴2、示例 演示:

    1、添加双坐标轴

    matplotlib.pyplot.twinx(ax=None)#制作并返回共享x轴的第二个轴。 matplotlib.pyplot.twiny(ax=None)#制作并返回共享y轴的第二个轴。

    2、示例

    in:

    import numpy as np #导入 numpyas import matplotlib.pyplot as plt #导入 matplotlib.pyplot x=np.arange(2,20,1) y1=x*x y2=np.log(x) fig=plt.figure() ax1=fig.add_subplot(111) ax1.plot(x,y1,'y',label='Y1') ax1.legend(loc =(0,0.92))#显示标签的位置(loc(浮点数,浮点数)) ax2=ax1.twinx()#生成双坐标 ax2.plot(x,y2,'r',label='Y2') ax2.legend(loc =(0,0.85))

    out:

    Processed: 0.014, SQL: 8