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

Method set_locs

lib/matplotlib/ticker.py:1299–1339  ·  view source on GitHub ↗
(self, locs)

Source from the content-addressed store, hash-verified

1297 self._minor_number = minor_number
1298
1299 def set_locs(self, locs):
1300 self._locs = np.array(locs)
1301 self._labelled.clear()
1302
1303 if not self._minor:
1304 return None
1305 if all(
1306 _is_decade(x, rtol=1e-7)
1307 or _is_decade(1 - x, rtol=1e-7)
1308 or (_is_close_to_int(2 * x) and
1309 int(np.round(2 * x)) == 1)
1310 for x in locs
1311 ):
1312 # minor ticks are subsample from ideal, so no label
1313 return None
1314 if len(locs) < self._minor_threshold:
1315 if len(locs) < self._minor_number:
1316 self._labelled.update(locs)
1317 else:
1318 # we do not have a lot of minor ticks, so only few decades are
1319 # displayed, then we choose some (spaced) minor ticks to label.
1320 # Only minor ticks are known, we assume it is sufficient to
1321 # choice which ticks are displayed.
1322 # For each ticks we compute the distance between the ticks and
1323 # the previous, and between the ticks and the next one. Ticks
1324 # with smallest minimum are chosen. As tiebreak, the ticks
1325 # with smallest sum is chosen.
1326 diff = np.diff(-np.log(1 / self._locs - 1))
1327 space_pessimistic = np.minimum(
1328 np.concatenate(((np.inf,), diff)),
1329 np.concatenate((diff, (np.inf,))),
1330 )
1331 space_sum = (
1332 np.concatenate(((0,), diff))
1333 + np.concatenate((diff, (0,)))
1334 )
1335 good_minor = sorted(
1336 range(len(self._locs)),
1337 key=lambda i: (space_pessimistic[i], space_sum[i]),
1338 )[-self._minor_number:]
1339 self._labelled.update(locs[i] for i in good_minor)
1340
1341 def _format_value(self, x, locs, sci_notation=True):
1342 if sci_notation:

Callers 3

test_basicMethod · 0.95
test_invalidMethod · 0.95
test_variablelengthMethod · 0.95

Calls 4

_is_decadeFunction · 0.85
_is_close_to_intFunction · 0.85
clearMethod · 0.45
updateMethod · 0.45

Tested by 3

test_basicMethod · 0.76
test_invalidMethod · 0.76
test_variablelengthMethod · 0.76