MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_sublabel

Method test_sublabel

lib/matplotlib/tests/test_ticker.py:1242–1282  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1240
1241 @mpl.style.context('default')
1242 def test_sublabel(self):
1243 # test label locator
1244 fig, ax = plt.subplots()
1245 ax.set_xscale('log')
1246 ax.xaxis.set_major_locator(mticker.LogLocator(base=10, subs=[]))
1247 ax.xaxis.set_minor_locator(mticker.LogLocator(base=10,
1248 subs=np.arange(2, 10)))
1249 ax.xaxis.set_major_formatter(mticker.LogFormatter(labelOnlyBase=True))
1250 ax.xaxis.set_minor_formatter(mticker.LogFormatter(labelOnlyBase=False))
1251 # axis range above 3 decades, only bases are labeled
1252 ax.set_xlim(1, 1e4)
1253 fmt = ax.xaxis.get_major_formatter()
1254 fmt.set_locs(ax.xaxis.get_majorticklocs())
1255 show_major_labels = [fmt(x) != ''
1256 for x in ax.xaxis.get_majorticklocs()]
1257 assert np.all(show_major_labels)
1258 self._sub_labels(ax.xaxis, subs=[])
1259
1260 # For the next two, if the numdec threshold in LogFormatter.set_locs
1261 # were 3, then the label sub would be 3 for 2-3 decades and (2, 5)
1262 # for 1-2 decades. With a threshold of 1, subs are not labeled.
1263 # axis range at 2 to 3 decades
1264 ax.set_xlim(1, 800)
1265 self._sub_labels(ax.xaxis, subs=[])
1266
1267 # axis range at 1 to 2 decades
1268 ax.set_xlim(1, 80)
1269 self._sub_labels(ax.xaxis, subs=[])
1270
1271 # axis range slightly more than 1 decade, but spanning a single major
1272 # tick, label subs 2, 3, 4, 6
1273 ax.set_xlim(.8, 9)
1274 self._sub_labels(ax.xaxis, subs=[2, 3, 4, 6])
1275
1276 # axis range at 0.4 to 1 decade, label subs 2, 3, 4, 6
1277 ax.set_xlim(1, 8)
1278 self._sub_labels(ax.xaxis, subs=[2, 3, 4, 6])
1279
1280 # axis range at 0 to 0.4 decade, label all
1281 ax.set_xlim(0.5, 0.9)
1282 self._sub_labels(ax.xaxis, subs=np.arange(2, 10, dtype=int))
1283
1284 @pytest.mark.parametrize('val', [1, 10, 100, 1000])
1285 def test_LogFormatter_call(self, val):

Callers

nothing calls this directly

Calls 12

_sub_labelsMethod · 0.95
fmtFunction · 0.85
set_xscaleMethod · 0.80
set_minor_locatorMethod · 0.80
set_minor_formatterMethod · 0.80
get_major_formatterMethod · 0.80
get_majorticklocsMethod · 0.80
subplotsMethod · 0.45
set_major_locatorMethod · 0.45
set_major_formatterMethod · 0.45
set_xlimMethod · 0.45
set_locsMethod · 0.45

Tested by

no test coverage detected