【问题标题】:Impose minor grid on plot with y log scale, using Python使用 Python 在具有 y 对数刻度的绘图上施加小网格
【发布时间】:2020-02-25 12:38:44
【问题描述】:

我正在用 mathplotlib 绘制一些图,y 轴是对数刻度。我想在 X 和 Y 轴上都有主要和次要网格。第一个图完美(意味着我的代码有效),而在第二个图中,y-minorgrid 被抑制(我假设是为了便于可视化)。我想克服这个并强加 y-minorgrid 的存在,即使结果图看起来不太清晰。 有什么建议吗? 当前代码是

    fig, axes = plt.subplots(1, 1, figsize=[18, 10])
    axes.plot(DF['value'])
    axes.set_title('whatever')
    axes.set_ylabel('Pressure [mbar]')
    axes.set_xlabel('time [s]')
    axes.set_yscale('log')
    axes.set_ylim([1E-8, 10000])
    axes.grid(b=True, which='minor', color='orange', linestyle=':')
    axes.grid(b=True, which='major')
    axes.minorticks_on()

【问题讨论】:

    标签: python grid logarithm


    【解决方案1】:

    看看下面的这篇文章,它可能对您的场景有所帮助。祝你好运!

    matplotlib: Setting both major and minor ticks forces same x and y scale

    【讨论】:

    • 嗨,尽管这不是我问题的答案,但了解如何手动设置刻度有点帮助。我的问题现在解决了,使用这个解决方案:axes.set_yscale('log') axes.legend(loc='best') axes.set_yticks(minor_ticks, minor=True) axes.set_yticks(major_ticks, minor=False) axes.grid(b=True, which='minor', color='orange', linestyle=':') axes.grid(b=True, which='major')
    猜你喜欢
    • 1970-01-01
    • 2020-06-20
    • 2012-05-08
    • 2016-12-12
    • 2015-07-22
    • 1970-01-01
    • 1970-01-01
    • 2019-01-05
    • 1970-01-01
    相关资源
    最近更新 更多