1

I am using a semilogy graph but I am struggling to get minor grid to turn on.

I am current using:

plt.grid(b=None, which='major', axis='both', color='k', linestyle='-', linewidth=0.5) plt.grid(b=None, which='minor', axis='both', color='r', linestyle='-', linewidth=0.2) 

but it isn't producing the minor grid only the major.

Update:

So my current code is:

 plt.semilogy(xPS[p-1]/1000, zPS[p-1]) plt.ylim(-1000000, 1000000) plt.xlim(0, 250) plt.grid(b=True, which='major', color='k', linestyle='-') plt.grid(b=True, which='minor', color='r', linestyle='-', alpha=0.2) plt.minorticks_on() plt.show() 

An I get an output like the image below with still not y-minor grid:

enter image description here

1 Answer 1

2

Try to add a minorticks_on call after the two above lines:

plt.minorticks_on() 

Full code:

import matplotlib.pyplot as plt plt.semilogy( [20,50,100,140,180,220,250], [2, 45*10, 314*10**2, 42*10**3, 475*10**3, 431*10**3, 904*10**3]) plt.ylim(1, 1000000) plt.xlim(0, 250) plt.grid(b=True, which='major', color='k', linestyle='-') plt.grid(b=True, which='minor', color='r', linestyle='-', alpha=0.2) plt.minorticks_on() plt.show() 

output

enter image description here

This is a known issue as explained in this discussion.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi, @Alexandre B. I tried this but its still not putting the minor axis on on the y.
@15002941 What's about the update ? Which Python Matplotlib version are you using ?
It's to do with the range of the y axis. If you increase to plt.ylim(0.0001, 1000000) then the minor gridlines are not plotted, probably in order to keep drawing speed relatively fast and to keep the plot from being overcrowded with gridlines

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.