@@ -19,8 +19,11 @@ Shading can be switched for the same data location, allowing
1919switches between ``nearest `` and ``gouraud ``, and now also
2020between ``flat `` and ``gouraud ``.
2121
22- For example::
22+ For example:
2323
24+ .. plot ::
25+ :include-source: true
26+ :alt: Switching between constant and linearly interpolated shading for data at corners and centers.
2427
2528 import matplotlib.pyplot as plt
2629 import numpy as np
@@ -30,12 +33,20 @@ For example::
3033 x = np.arange(ncols + 1)
3134 y = np.arange(nrows + 1)
3235
33- fig, ax = plt.subplots()
36+ fig, axs = plt.subplots(2, 2, layout='constrained' )
3437
35- # Data at corners, requires X and Y one larger than Z.
36- ax .pcolormesh(x, y, Z, shading='flat ')
37- ax.pcolormesh(x, y , Z, shading='gouraud ')
38+ # Data at corners, requires X and Y the same shape as Z.
39+ axs[0, 0] .pcolormesh(x[:-1] , y[:-1] , Z, shading='nearest ')
40+ axs[0, 0].set_title('nearest: X, Y , Z same shape ')
3841
39- # Data at centers, requires X and Y the same shape as Z.
40- ax.pcolormesh(x[:-1], y[:-1], Z, shading='nearest')
41- ax.pcolormesh(x[:-1], y[:-1], Z, shading='gouraud')
42+ axs[0, 1].pcolormesh(x[:-1], y[:-1], Z, shading='gouraud')
43+ axs[0, 1].set_title('gouraud: X, Y, Z same shape')
44+
45+ # Data at centers, requires X and Y one larger than Z.
46+ axs[1, 0].pcolormesh(x, y, Z, shading='flat')
47+ axs[1, 0].set_title('flat: X, Y one larger than Z')
48+
49+ axs[1, 1].pcolormesh(x, y, Z, shading='gouraud')
50+ axs[1, 1].set_title('gouraud: X, Y one larger than Z')
51+
52+ plt.show()
0 commit comments