Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
In matplotlib, I am unable to get a grid in the following code (which has a log y axis spanning less than a decade without crossing a power of 10).
from matplotlib import pyplot as plt
import matplotlib.ticker as ticker
import numpy as np
x = np.geomspace(0.001,5,101)
y = 10**(-0.2-0.05*(np.log10(x)+0.5)**2)
plt.figure(figsize=[5,5])
ax = plt.gca()
plt.plot(x,y)
plt.xscale('log')
plt.yscale('log')
plt.xlabel('$x$')
plt.ylabel('$y$')
yticks = [0.2,0.3,0.4,0.5,0.6] # should not need to be set!
ax.yaxis.set_major_locator(ticker.FixedLocator(yticks)) # why so complicated?
plt.grid()
unless, I remove
axes.grid : True
from my matplotlibrc. Is there a solution that does not involve editing my matplotlibrc file every time I run into a narrow log axis, nor deleting axes.grid : True
in my matplotlibrc file, which would force me include plt.grid
in my plots?
My other lines involving grids in my matplotlibrc are
axes.grid.axis : both ## which axis the grid should apply to
axes.grid.which : major ## gridlines at major, minor or both ticks
grid.linestyle : dotted ## was solid
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.