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

Function test_violinplot_alpha

lib/matplotlib/tests/test_axes.py:4423–4447  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4421
4422
4423def test_violinplot_alpha():
4424 matplotlib.style.use('default')
4425 data = [(np.random.normal(0, 1, 100))]
4426
4427 fig, ax = plt.subplots()
4428 parts = ax.violinplot(data, positions=[1])
4429
4430 # Case 1: If facecolor is unspecified, it's the first color from the color cycle
4431 # with Artist-level alpha=0.3
4432 facecolor = ('y' if mpl.rcParams['_internal.classic_mode']
4433 else plt.rcParams['axes.prop_cycle'].by_key()['color'][0])
4434 assert mcolors.same_color(parts['bodies'][0].get_facecolor(), (facecolor, 0.3))
4435 assert parts['bodies'][0].get_alpha() == 0.3
4436 # setting a new facecolor maintains the alpha
4437 parts['bodies'][0].set_facecolor('red')
4438 assert mcolors.same_color(parts['bodies'][0].get_facecolor(), ('red', 0.3))
4439
4440 # Case 2: If facecolor is explicitly given, it's alpha does not become an
4441 # Artist property
4442 parts = ax.violinplot(data, positions=[1], facecolor=('blue', 0.3))
4443 assert mcolors.same_color(parts['bodies'][0].get_facecolor(), ('blue', 0.3))
4444 assert parts['bodies'][0].get_alpha() is None
4445 # so setting a new color does not maintain the alpha
4446 parts['bodies'][0].set_facecolor('red')
4447 assert mcolors.same_color(parts['bodies'][0].get_facecolor(), 'red')
4448
4449
4450@check_figures_equal()

Callers

nothing calls this directly

Calls 5

violinplotMethod · 0.80
subplotsMethod · 0.45
get_facecolorMethod · 0.45
get_alphaMethod · 0.45
set_facecolorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…