Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1c44544

Browse files
committed
Adding a whats new entry for pcolormesh snapping.
1 parent ecd94f0 commit 1c44544

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
pcolormesh has improved transparency handling by enabling sub-pixel snapping
2+
----------------------------------------------------------------------------
3+
4+
Due to how the snapping keyword argument was getting passed to the AGG backend,
5+
previous versions of Matplotlib would appear to show lines between the grid
6+
edges of a mesh with transparency. This version now applies snapping
7+
by default. To restore the old behavior (e.g., for test images), you may set
8+
:rc:`pcolormesh.snap` to `False`.
9+
10+
.. plot::
11+
12+
import matplotlib.pyplot as plt
13+
import numpy as np
14+
15+
# Use old pcolormesh snapping values
16+
plt.rcParams['pcolormesh.snap'] = False
17+
fig, ax = plt.subplots()
18+
xx, yy = np.meshgrid(np.arange(10), np.arange(10))
19+
z = (xx + 1) * (yy + 1)
20+
mesh = ax.pcolormesh(xx, yy, z, shading='auto', alpha=0.5)
21+
fig.colorbar(mesh, orientation='vertical')
22+
ax.set_title('Before (pcolormesh.snap = False)')
23+
24+
Note that there are lines between the grid boundaries of the main plot which
25+
are not the same transparency. The colorbar also shows these lines when a
26+
transparency is added to the colormap because internally it uses pcolormesh
27+
to draw the colorbar. With snapping on by default (below), the lines
28+
at the grid boundaries disappear.
29+
30+
.. plot::
31+
32+
import matplotlib.pyplot as plt
33+
import numpy as np
34+
35+
fig, ax = plt.subplots()
36+
xx, yy = np.meshgrid(np.arange(10), np.arange(10))
37+
z = (xx + 1) * (yy + 1)
38+
mesh = ax.pcolormesh(xx, yy, z, shading='auto', alpha=0.5)
39+
fig.colorbar(mesh, orientation='vertical')
40+
ax.set_title('After (default: pcolormesh.snap = True)')

0 commit comments

Comments
 (0)