|
| 1 | +import numpy as np |
| 2 | +import matplotlib.pyplot as plt |
| 3 | + |
| 4 | +d = np.arange(100).reshape(10, 10) |
| 5 | +x, y = np.meshgrid(np.arange(11), np.arange(11)) |
| 6 | + |
| 7 | +theta = 0.25*np.pi |
| 8 | +xx = x*np.cos(theta) - y*np.sin(theta) |
| 9 | +yy = x*np.sin(theta) + y*np.cos(theta) |
| 10 | + |
| 11 | +ax1 = plt.subplot(221) |
| 12 | +ax1.set_aspect(1) |
| 13 | +ax1.pcolormesh(xx, yy, d) |
| 14 | +ax1.set_title("No Rasterization") |
| 15 | + |
| 16 | +ax2 = plt.subplot(222) |
| 17 | +ax2.set_aspect(1) |
| 18 | +ax2.set_title("Rasterization") |
| 19 | + |
| 20 | +m = ax2.pcolormesh(xx, yy, d) |
| 21 | +m.set_rasterized(True) |
| 22 | + |
| 23 | +ax3 = plt.subplot(223) |
| 24 | +ax3.set_aspect(1) |
| 25 | +ax3.pcolormesh(xx, yy, d) |
| 26 | +ax3.text(0.5, 0.5, "Text", alpha=0.2, |
| 27 | + va="center", ha="center", size=50, transform=ax3.transAxes) |
| 28 | + |
| 29 | +ax3.set_title("No Rasterization") |
| 30 | + |
| 31 | + |
| 32 | +ax4 = plt.subplot(224) |
| 33 | +ax4.set_aspect(1) |
| 34 | +m = ax4.pcolormesh(xx, yy, d) |
| 35 | +m.set_zorder(-20) |
| 36 | + |
| 37 | +ax4.text(0.5, 0.5, "Text", alpha=0.2, |
| 38 | + zorder=-15, |
| 39 | + va="center", ha="center", size=50, transform=ax4.transAxes) |
| 40 | + |
| 41 | +ax4.set_rasterization_zorder(-10) |
| 42 | + |
| 43 | +ax4.set_title("Rasterization z$<-10$") |
| 44 | + |
| 45 | + |
| 46 | +# ax2.title.set_rasterized(True) # should display a warning |
| 47 | + |
| 48 | +plt.savefig("test_rasterization.pdf", dpi=150) |
| 49 | +plt.savefig("test_rasterization.eps", dpi=150) |
| 50 | + |
| 51 | +if not plt.rcParams["text.usetex"]: |
| 52 | + plt.savefig("test_rasterization.svg", dpi=150) |
| 53 | + # svg backend currently ignores the dpi |
0 commit comments