【问题标题】:How can a limit of an axis be required to be greater than or equal to 0 in matplotlib?matplotlib中如何要求轴的限制大于或等于0?
【发布时间】:2015-11-17 22:33:18
【问题描述】:

我想设置一个y轴的下限大于等于0的要求,我确实想把y轴的下限设置为正好0.

我不想将 y 轴最小限制设置为 0,因为绘图如下:

我想要求 y 轴的最小限制大于或等于 0,而不是完全设置为 0,以便绘图如下所示:

那么,我应该怎么做而不是下面的呢?

axes = matplotlib.pyplot.gca()
axes.xaxis.set_major_formatter(FormatStrFormatter("%.0f"))
axes.yaxis.set_major_formatter(FormatStrFormatter("%.0f"))
axes.set_xlim(left = 0)
axes.set_ylim(bottom = 0)

【问题讨论】:

    标签: python matplotlib limit axes


    【解决方案1】:

    使用get_xlimget_ylim 获取自动生成的限制。然后取下限的最大值和 0 并在 set_xlimset_ylim 中使用。

    【讨论】:

    • 那是完美的。非常感谢您提供有关 get_*lim 方法的详细信息。
    猜你喜欢
    • 2022-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-15
    • 2011-01-25
    • 2013-09-02
    • 1970-01-01
    • 2020-06-30
    相关资源
    最近更新 更多