Bug report
Bug summary
Using matplotlib 3.4.1 on a fresh miniconda installation, trying to add a grid to an axis can return an error.
It seems to be linked with the "reset" option of the tick_param function of an axis, if the function has been used just before adding the grid. Activating the option seems to cause the issue; removing the option makes everything work.
Code for reproduction
fig, axes = plt.subplots(1, 4, sharey= True)
# This doesn't work
for axis in axes:
axis.tick_params(reset = True, axis='both', which='major', labelsize= 10, right = False, top = False)
for axis in axes:
axis.grid(color = "gainsboro", linestyle='-', linewidth=0.5)
axis.set_facecolor('#FCFCFC')
# This works
for axis in axes:
axis.tick_params(reset = False, axis='both', which='major', labelsize= 10, right = False, top = False)
for axis in axes:
axis.grid(color = "gainsboro", linestyle='-', linewidth=0.5)
axis.set_facecolor('#FCFCFC')
Actual outcome
File "C:\ProgramData\Miniconda3\lib\site-packages\matplotlib\axis.py", line 1414, in grid
gridkw['gridOn'] = not self._major_tick_kw['gridOn']
KeyError: 'gridOn'
Expected outcome
The grid is expected to be added to the figure without any issue, resulting in the following appearance :

Matplotlib version
- Operating system: Windows 10
- Matplotlib version (
import matplotlib; print(matplotlib.__version__)): 3.4.1
- Matplotlib backend (
print(matplotlib.get_backend())): Qt5Agg
- Python version: 3.9.1
Matplotlib was installed via the anaconda command prompt, using conda install -c conda-forge matplotlib.
Bug report
Bug summary
Using matplotlib 3.4.1 on a fresh miniconda installation, trying to add a grid to an axis can return an error.
It seems to be linked with the "reset" option of the tick_param function of an axis, if the function has been used just before adding the grid. Activating the option seems to cause the issue; removing the option makes everything work.
Code for reproduction
Actual outcome
Expected outcome
The grid is expected to be added to the figure without any issue, resulting in the following appearance :
Matplotlib version
import matplotlib; print(matplotlib.__version__)): 3.4.1print(matplotlib.get_backend())): Qt5AggMatplotlib was installed via the anaconda command prompt, using
conda install -c conda-forge matplotlib.