Search code examples
pythongridlogarithm

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


I'm making some plots with mathplotlib, the y axis is in log scale. I want to have both major and minor grids on both X and Y axis. The first plot comes out perfect (meaning that my code works), while in the second plot the y-minorgrid is suppressed (I assume for ease of visualisation reasons). I want to overcome this and impose the presence of y-minorgrid, even if the resulting plot looks less clear. Any suggestion? Current code is

    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()

Solution

  • take a look at this post below that may be helpful to your scenario. Good luck!

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