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

Skip to content

Commit f794206

Browse files
authored
Merge pull request #18121 from timhoffm/rasterization
Improve rasterization demo
2 parents e54cf8f + 08ca355 commit f794206

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

examples/misc/rasterization_demo.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
yy = x*np.sin(theta) + y*np.cos(theta) # rotate y by -theta
2929

3030
# Plot the rasterized and non-rasterized plot
31-
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)
31+
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, constrained_layout=True)
3232

3333
# Create a pseudocolor non-rastertized plot with a non-regular rectangular grid
3434
ax1.set_aspect(1)
@@ -38,9 +38,7 @@
3838
# Create a pseudocolor rastertized plot with a non-regular rectangular grid
3939
ax2.set_aspect(1)
4040
ax2.set_title("Rasterization")
41-
m = ax2.pcolormesh(xx, yy, d)
42-
# Force rasterized drawing in vector backend output
43-
m.set_rasterized(True)
41+
m = ax2.pcolormesh(xx, yy, d, rasterized=True)
4442

4543
# Create a pseudocolor non-rastertized plot with a non-regular rectangular
4644
# grid and an overlapped "Text"
@@ -53,10 +51,8 @@
5351
# Create a pseudocolor rastertized plot with a non-regular rectangular
5452
# grid and an overlapped "Text"
5553
ax4.set_aspect(1)
56-
m = ax4.pcolormesh(xx, yy, d)
57-
m.set_zorder(-20)
58-
ax4.text(0.5, 0.5, "Text", alpha=0.2,
59-
zorder=-15,
54+
m = ax4.pcolormesh(xx, yy, d, zorder=-20)
55+
ax4.text(0.5, 0.5, "Text", alpha=0.2, zorder=-15,
6056
va="center", ha="center", size=50, transform=ax4.transAxes)
6157
# Set zorder value below which artists will be rasterized
6258
ax4.set_rasterization_zorder(-10)

0 commit comments

Comments
 (0)