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

Function test_contourf_legend_elements

lib/matplotlib/tests/test_contour.py:616–635  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

614
615
616def test_contourf_legend_elements():
617 from matplotlib.patches import Rectangle
618 x = np.arange(1, 10)
619 y = x.reshape(-1, 1)
620 h = x * y
621
622 cs = plt.contourf(h, levels=[10, 30, 50],
623 colors=['#FFFF00', '#FF00FF', '#00FFFF'],
624 extend='both')
625 cs.cmap = cs.cmap.with_extremes(over='red', under='blue')
626 cs.changed()
627 artists, labels = cs.legend_elements()
628 assert labels == ['$x \\leq -1e+250s$',
629 '$10.0 < x \\leq 30.0$',
630 '$30.0 < x \\leq 50.0$',
631 '$x > 1e+250s$']
632 expected_colors = ('blue', '#FFFF00', '#FF00FF', 'red')
633 assert all(isinstance(a, Rectangle) for a in artists)
634 assert all(same_color(a.get_facecolor(), c)
635 for a, c in zip(artists, expected_colors))
636
637
638def test_contour_legend_elements():

Callers

nothing calls this directly

Calls 6

same_colorFunction · 0.90
contourfMethod · 0.45
with_extremesMethod · 0.45
changedMethod · 0.45
legend_elementsMethod · 0.45
get_facecolorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…