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

Function test_warn_big_data_best_loc

lib/matplotlib/tests/test_legend.py:1316–1337  ·  view source on GitHub ↗
(monkeypatch)

Source from the content-addressed store, hash-verified

1314
1315
1316def test_warn_big_data_best_loc(monkeypatch):
1317 # Force _find_best_position to think it took a long time.
1318 counter = itertools.count(0, step=1.5)
1319 monkeypatch.setattr(time, 'perf_counter', lambda: next(counter))
1320
1321 fig, ax = plt.subplots()
1322 fig.canvas.draw() # So that we can call draw_artist later.
1323
1324 # Place line across all possible legend locations.
1325 x = [0.9, 0.1, 0.1, 0.9, 0.9, 0.5]
1326 y = [0.95, 0.95, 0.05, 0.05, 0.5, 0.5]
1327 ax.plot(x, y, 'o-', label='line')
1328
1329 with rc_context({'legend.loc': 'best'}):
1330 legend = ax.legend()
1331 with pytest.warns(UserWarning,
1332 match='Creating legend with loc="best" can be slow with large '
1333 'amounts of data.') as records:
1334 fig.draw_artist(legend) # Don't bother drawing the lines -- it's slow.
1335 # The _find_best_position method of Legend is called twice, duplicating
1336 # the warning message.
1337 assert len(records) == 2
1338
1339
1340def test_no_warn_big_data_when_loc_specified(monkeypatch):

Callers

nothing calls this directly

Calls 7

rc_contextFunction · 0.90
countMethod · 0.80
subplotsMethod · 0.45
drawMethod · 0.45
plotMethod · 0.45
legendMethod · 0.45
draw_artistMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…