@@ -1290,26 +1290,53 @@ def _set_artist_props(self, a):
12901290 return
12911291 a .set_figure (self .get_figure (root = False ))
12921292
1293+ @staticmethod
1294+ def _tick_group_visible (kw ):
1295+ """
1296+ Check if any of the tick group components are visible.
1297+ Takes in self._major_tick_kw or self._minor_tick_kw.
1298+ """
1299+ return (kw .get ('tick1On' ) is not False or
1300+ kw .get ('tick2On' ) is not False or
1301+ kw .get ('label1On' ) is not False or
1302+ kw .get ('label2On' ) is not False or
1303+ kw .get ('gridOn' ) is not False )
1304+
12931305 def _update_ticks (self ):
12941306 """
12951307 Update ticks (position and labels) using the current data interval of
12961308 the axes. Return the list of ticks that will be drawn.
12971309 """
1298- major_locs = self .get_majorticklocs ()
1299- major_labels = self .major .formatter .format_ticks (major_locs )
1300- major_ticks = self .get_major_ticks (len (major_locs ))
1301- for tick , loc , label in zip (major_ticks , major_locs , major_labels ):
1302- tick .update_position (loc )
1303- tick .label1 .set_text (label )
1304- tick .label2 .set_text (label )
1305- minor_locs = self .get_minorticklocs ()
1306- minor_labels = self .minor .formatter .format_ticks (minor_locs )
1307- minor_ticks = self .get_minor_ticks (len (minor_locs ))
1308- for tick , loc , label in zip (minor_ticks , minor_locs , minor_labels ):
1309- tick .update_position (loc )
1310- tick .label1 .set_text (label )
1311- tick .label2 .set_text (label )
1310+ # Check if major ticks should be computed.
1311+ # Skip if using NullLocator or if all visible components are off.
1312+ if (self ._tick_group_visible (self ._major_tick_kw )
1313+ and not isinstance (self .get_major_locator (), NullLocator )):
1314+ major_locs = self .get_majorticklocs ()
1315+ major_labels = self .major .formatter .format_ticks (major_locs )
1316+ major_ticks = self .get_major_ticks (len (major_locs ))
1317+ for tick , loc , label in zip (major_ticks , major_locs , major_labels ):
1318+ tick .update_position (loc )
1319+ tick .label1 .set_text (label )
1320+ tick .label2 .set_text (label )
1321+ else :
1322+ major_ticks = []
1323+
1324+ # Check if minor ticks should be computed.
1325+ if (self ._tick_group_visible (self ._minor_tick_kw )
1326+ and not isinstance (self .get_minor_locator (), NullLocator )):
1327+ minor_locs = self .get_minorticklocs ()
1328+ minor_labels = self .minor .formatter .format_ticks (minor_locs )
1329+ minor_ticks = self .get_minor_ticks (len (minor_locs ))
1330+ for tick , loc , label in zip (minor_ticks , minor_locs , minor_labels ):
1331+ tick .update_position (loc )
1332+ tick .label1 .set_text (label )
1333+ tick .label2 .set_text (label )
1334+ else :
1335+ minor_ticks = []
1336+
13121337 ticks = [* major_ticks , * minor_ticks ]
1338+ if not ticks :
1339+ return []
13131340
13141341 view_low , view_high = self .get_view_interval ()
13151342 if view_low > view_high :
0 commit comments