@@ -1295,20 +1295,47 @@ def _update_ticks(self):
12951295 Update ticks (position and labels) using the current data interval of
12961296 the axes. Return the list of ticks that will be drawn.
12971297 """
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 )
1298+ # Check if major ticks should be computed.
1299+ # Skip if using NullLocator or if all visible components are off.
1300+ major_kw = self ._major_tick_kw
1301+ major_visible = (major_kw .get ('tick1On' ) is not False or
1302+ major_kw .get ('tick2On' ) is not False or
1303+ major_kw .get ('label1On' ) is not False or
1304+ major_kw .get ('label2On' ) is not False or
1305+ major_kw .get ('gridOn' ) is not False )
1306+
1307+ if (major_visible
1308+ and not isinstance (self .get_major_locator (), NullLocator )):
1309+ major_locs = self .get_majorticklocs ()
1310+ major_labels = self .major .formatter .format_ticks (major_locs )
1311+ major_ticks = self .get_major_ticks (len (major_locs ))
1312+ for tick , loc , label in zip (major_ticks , major_locs , major_labels ):
1313+ tick .update_position (loc )
1314+ tick .label1 .set_text (label )
1315+ tick .label2 .set_text (label )
1316+ else :
1317+ major_ticks = []
1318+
1319+ # Check if minor ticks should be computed.
1320+ minor_kw = self ._minor_tick_kw
1321+ minor_visible = (minor_kw .get ('tick1On' ) is not False or
1322+ minor_kw .get ('tick2On' ) is not False or
1323+ minor_kw .get ('label1On' ) is not False or
1324+ minor_kw .get ('label2On' ) is not False or
1325+ minor_kw .get ('gridOn' ) is not False )
1326+
1327+ if (minor_visible
1328+ and not isinstance (self .get_minor_locator (), NullLocator )):
1329+ minor_locs = self .get_minorticklocs ()
1330+ minor_labels = self .minor .formatter .format_ticks (minor_locs )
1331+ minor_ticks = self .get_minor_ticks (len (minor_locs ))
1332+ for tick , loc , label in zip (minor_ticks , minor_locs , minor_labels ):
1333+ tick .update_position (loc )
1334+ tick .label1 .set_text (label )
1335+ tick .label2 .set_text (label )
1336+ else :
1337+ minor_ticks = []
1338+
13121339 ticks = [* major_ticks , * minor_ticks ]
13131340
13141341 view_low , view_high = self .get_view_interval ()
0 commit comments