@@ -295,9 +295,23 @@ def _grid(self, obj, data):
295
295
# Don't use get_{x,y}gridlines for gridlines; see discussion on
296
296
# <http://sourceforge.net/p/matplotlib/mailman/message/25169234/> Coordinate of
297
297
# the lines are entirely meaningless, but styles (colors,...) are respected.
298
- if obj .xaxis ._gridOnMajor :
298
+
299
+ try :
300
+ # mpl 3.3.3+
301
+ # <https://github.com/matplotlib/matplotlib/pull/18769>
302
+ has_major_xgrid = obj .xaxis ._major_tick_kw ["gridOn" ]
303
+ has_minor_xgrid = obj .xaxis ._minor_tick_kw ["gridOn" ]
304
+ has_major_ygrid = obj .yaxis ._major_tick_kw ["gridOn" ]
305
+ has_minor_ygrid = obj .yaxis ._minor_tick_kw ["gridOn" ]
306
+ except KeyError :
307
+ has_major_xgrid = obj .xaxis ._gridOnMajor
308
+ has_minor_xgrid = obj .xaxis ._gridOnMinor
309
+ has_major_ygrid = obj .yaxis ._gridOnMajor
310
+ has_minor_ygrid = obj .yaxis ._gridOnMinor
311
+
312
+ if has_major_xgrid :
299
313
self .axis_options .append ("xmajorgrids" )
300
- if obj . xaxis . _gridOnMinor :
314
+ if has_minor_xgrid :
301
315
self .axis_options .append ("xminorgrids" )
302
316
303
317
xlines = obj .get_xgridlines ()
@@ -307,9 +321,9 @@ def _grid(self, obj, data):
307
321
if col != "black" :
308
322
self .axis_options .append (f"x grid style={{{ col } }}" )
309
323
310
- if obj . yaxis . _gridOnMajor :
324
+ if has_major_ygrid :
311
325
self .axis_options .append ("ymajorgrids" )
312
- if obj . yaxis . _gridOnMinor :
326
+ if has_minor_ygrid :
313
327
self .axis_options .append ("yminorgrids" )
314
328
315
329
ylines = obj .get_ygridlines ()
0 commit comments