【问题标题】:matplotlib.pyplot: add horizontal line to sub-plot [duplicate]matplotlib.pyplot:向子图添加水平线
【发布时间】:2018-09-17 12:48:03
【问题描述】:

这段代码(matplotlib.pyplot)在下面的链接中给出了图:

plt.subplot(2, 1, 1)
plt.plot(px,py)

plt.subplot(2, 1, 2)
plt.plot(curve)

2 plots example --> 我想在第二个子图中在 100.000 处添加一条水平线。我怎样才能做到这一点?两个图的颜色应保持相同/同步。

【问题讨论】:

    标签: python matplotlib plot line


    【解决方案1】:

    您可以使用 matplotlib 的matplotlib.axes.Axes.axhline,它会在轴上添加一条水平线。如需进一步设置参数,请参考official documentation

    import matplotlib.pyplot as plt    
    plt.axhline(100000, color="gray")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-07
      • 2021-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多