使用 Python 在具有 y 对数刻度的地块上施加次要网格

Impose minor grid on plot with y log scale, using Python

我正在用 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()

请查看下面的 post,它可能对您的情况有所帮助。祝你好运!

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