You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pcolor vs pcolorfast: unexpected white edgecolors using RGBA-alike colormaps #10115
When using pcolor and pcolorfast to plot the same image using alpha channels of colormaps, and then savefig to a pdf file, there is evident white edges in the one saved by pcolor. However, pcolorfast has visually more appealing results.
Code for reproduction
importnumpyasnpimportmatplotlibasmplimportmatplotlib.pyplotaspltdefrgba_blues():
"""white -> blue, with alpha channel"""cdict= {'red': ((0.0, 0.0, 0.0),
(1.0, 0.0, 0.0)),
'green': ((0.0, 0.0, 0.0),
(1.0, 0.0, 0.0)),
'blue': ((0.0, 0.0, 0.0),
(0.25, 0.5, 0.5), # enable blue
(1.0, 1.0, 1.0)),
'alpha': ((0.0, 0.0, 0.0),
(0.25, 0.5, 0.5),
(1.0, 1.0, 0.0))}
# c = mpl.colors.LinearSegmentedColormap.from_list("", ["white", "blue"])c=mpl.colors.LinearSegmentedColormap('blues', cdict)
returnc# Linear x array for cell centers:x=np.arange(32)
y=np.arange(32)
z=x[:, np.newaxis].dot(y[:, np.newaxis].transpose())
# plot using pcolorcmap=rgba_blues()
fig, ax=plt.subplots()
ax.pcolor(x, y, z, cmap=cmap, edgecolors='none', antialiased=True)
plt.show()
fig.savefig('pcolor.pdf')
# plot using pcolorfastcmap=rgba_blues()
fig, ax=plt.subplots()
ax.pcolorfast(x, y, z, cmap=cmap)
plt.show()
fig.savefig('pcolorfast.pdf')
Actual outcome
see pcolor.pdf and pcolorfast.pdf
Expected outcome
can we remove the unwanted edgecolors in pcolor when using the alpha channels of colormap?
BTW: the quadmesh edges are also in white color when using the alpha channels in pcolormesh. I think these edges should also be removed if we specify edgecolors='none'.
When using pcolormesh, what I get in pdf is not the same as in the qt backend.
cmap=rgba_blues()
fig, ax=plt.subplots()
ax.pcolormesh(x, y, z, cmap=cmap, shading='gouraud')
plt.show()
BTW: can we have a pcolor that supports interpolating features?
This is not a bug, it is a fundamental limitation of the rendering algorithm that we encounter in many contexts. I suggest turning anti-aliasing off. Some other points and answers:
Please note that pcolor, pcolormesh (with one unfortunate exceptional case), and pcolorfast are all designed for filling regions specified by their edges. They are not intended for regions specified based on their centers.
These functions have different strengths and weaknesses, and use quite different algorithms. Pcolor is slow and should be avoided unless its particular characteristics are required; in most cases, pcolormesh is a better substitute. Pcolorfast uses different algorithms, and returns different objects, depending on the characteristics of the boundary grid that is supplied. The fastest available algorithm is used. For your test case, that is actually the same algorithm as is used in imshow.
When you display a pdf, the rendering is being done by a different engine than when you plot to the screen, so it is common for the boundaries between colored regions to be rendered differently.
Pcolor is not intended or suitable for interpolation. For interpolation, use imshow.
@anntzer, I think you gave the best explanation of the edge rendering problem some time in the last few months in reply to another in the long series of issues about this. If you can easily find it, please insert a reference to it here. Thank you.
Thanks, I will use pcolorfast instead. imshow has the interpolation capability, however, we can not use imshow(X, Y, Z) with coordinates data where Z=f(X, Y)
@jklymak In your post, pdf rendering using alpha values is really a problem. The lines are more visible (seems like their alpha channels are doubled and they produce unwanted results).
Activity
efiring commentedon Dec 27, 2017
This is not a bug, it is a fundamental limitation of the rendering algorithm that we encounter in many contexts. I suggest turning anti-aliasing off. Some other points and answers:
efiring commentedon Dec 27, 2017
@anntzer, I think you gave the best explanation of the edge rendering problem some time in the last few months in reply to another in the long series of issues about this. If you can easily find it, please insert a reference to it here. Thank you.
jklymak commentedon Dec 27, 2017
I did a little writeup based on what @anntzer said, though I see that I failed to include his links...
https://github.com/jklymak/contourfIssues
anntzer commentedon Dec 27, 2017
#9574 (comment) and #7841.
liubenyuan commentedon Dec 28, 2017
Thanks, I will use
pcolorfastinstead.imshowhas the interpolation capability, however, we can not use imshow(X, Y, Z) with coordinates data where Z=f(X, Y)liubenyuan commentedon Dec 28, 2017
@jklymak In your post, pdf rendering using alpha values is really a problem. The lines are more visible (seems like their alpha channels are doubled and they produce unwanted results).