Building on the answer by @eqzx:
If you set alpha=1, you will get better results as far as grid lines are concerned. However, your application/use case may differ.
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 100)
y = np.linspace(0, 10, 100)
xx, yy = np.meshgrid(x, y)
zz = xx**2 + yy*2
fig, axes = plt.subplots(2,3, figsize=(15,5))
axes[0,0].pcolormesh(XX, YY, ZZ_r, zorder=-1, cmap='magma', alpha=0.5, antialiased=True)
axes[0,1].pcolormesh(XX, YY, ZZ_r, zorder=-1, cmap='magma', alpha=0.5, antialiased=True, linewidth=0.0)
axes[0,2].pcolormesh(XX, YY, ZZ_r, zorder=-1, cmap='magma', alpha=0.5, antialiased=False, linewidth=0.0)
axes[1,0].pcolormesh(XX, YY, ZZ_r, zorder=-1, cmap='magma', alpha=1, antialiased=True)
axes[1,1].pcolormesh(XX, YY, ZZ_r, zorder=-1, cmap='magma', alpha=1, antialiased=True, linewidth=0.0)
axes[1,2].pcolormesh(XX, YY, ZZ_r, zorder=-1, cmap='magma', alpha=1, antialiased=False, linewidth=0.0)
See plot here
pcolormeshactually draws individual rectangles, and some pdf viewers render them differently than others. Both as a workaround and because it's more efficient, it's better to useimshowin this case. For example, in your case:plt.imshow(z, interpolation='nearest', cmap='Blues', extent=[x.min(), x.max(), y.min(), y.max()]). - Joe Kingtonrasterized=Truetocolorbar. - Joe Kingtonpl.colorbar(rasterized=True). With MPL version 1.3.1 and 1.4.x. The top answer on this question works for me. - farenorthcb.solids.set_rasterized(True)- hanno