()
| 4421 | |
| 4422 | |
| 4423 | def 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() |
nothing calls this directly
no test coverage detected
searching dependent graphs…