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

Function test_pcolormesh_alpha

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

Source from the content-addressed store, hash-verified

1474 style='_classic_test',
1475 tol=0.4 if platform.machine() == "aarch64" else 0)
1476def test_pcolormesh_alpha():
1477 # Remove this line when this test image is regenerated.
1478 plt.rcParams['pcolormesh.snap'] = False
1479
1480 n = 12
1481 X, Y = np.meshgrid(
1482 np.linspace(-1.5, 1.5, n),
1483 np.linspace(-1.5, 1.5, n*2)
1484 )
1485 Qx = X
1486 Qy = Y + np.sin(X)
1487 Z = np.hypot(X, Y) / 5
1488 Z = (Z - Z.min()) / np.ptp(Z)
1489 vir = mpl.colormaps["viridis"].resampled(16)
1490 # make another colormap with varying alpha
1491 colors = vir(np.arange(16))
1492 colors[:, 3] = 0.5 + 0.5*np.sin(np.arange(16))
1493 cmap = mcolors.ListedColormap(colors)
1494
1495 fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)
1496 for ax in ax1, ax2, ax3, ax4:
1497 ax.add_patch(mpatches.Rectangle(
1498 (0, -1.5), 1.5, 3, facecolor=[.7, .1, .1, .5], zorder=0
1499 ))
1500 # ax1, ax2: constant alpha
1501 ax1.pcolormesh(Qx, Qy, Z[:-1, :-1], cmap=vir, alpha=0.4,
1502 shading='flat', zorder=1)
1503 ax2.pcolormesh(Qx, Qy, Z, cmap=vir, alpha=0.4, shading='gouraud', zorder=1)
1504 # ax3, ax4: alpha from colormap
1505 ax3.pcolormesh(Qx, Qy, Z[:-1, :-1], cmap=cmap, shading='flat', zorder=1)
1506 ax4.pcolormesh(Qx, Qy, Z, cmap=cmap, shading='gouraud', zorder=1)
1507
1508
1509@pytest.mark.parametrize("dims,alpha", [(3, 1), (4, 0.5)])

Callers

nothing calls this directly

Calls 5

minMethod · 0.80
add_patchMethod · 0.80
pcolormeshMethod · 0.80
resampledMethod · 0.45
subplotsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…