Repository navigation
FEATURE: Alpha channel in Gouraud triangles in the pdf backend - #14414
Conversation
Instead of the `self.nextFoo` counters. This way the various name sequences are defined closer together and it's impossible to forget to increment the counters.
draw_markers has been implemented, draw_line_collection was removed years ago but draw_quad_mesh could be implemented
and delete a useless comment
|
I agree that the grey looks wrong, but it could be a result of alpha blending with the white background. The alpha channel is effectively Gouraud interpolated between adjacent vertices, but I wonder if it should just be set to zero for the whole triangle where at least one vertex is masked out. I think that would correspond better to my intuition of how to show missing data, but I suppose in some use cases you might want to blend continuously with the background. The Agg results look like the renderer is doing linear interpolation for alpha inside the triangles but drawing the edges with opaque colors. |
|
Of course the grey color is because all of the RGBA channels are interpolated between the data color and zero. If you zoom in (on either the png or the pdf) the grey areas closest to the data are tinted with the data color. Here's a variant where the masked data is given another color: from matplotlib import cm, pyplot as plt
import numpy as np
import matplotlib
matplotlib.use('agg')
X, Y = np.meshgrid(
np.linspace(0, 10, 31),
np.linspace(0, 10, 8)
)
mesh = plt.pcolormesh(
X,
Y + 3*np.sin(X),
np.ma.masked_where(np.abs(Y-5)<2, X),
shading='gouraud',
cmap='jet',
)
mesh.get_cmap()._rgba_bad = (1.0, 0.0, 1.0, 0.3)
plt.savefig('example.png')
plt.savefig('example.pdf')png and pdf images: The question is, who are using pcolormesh and for what purpose, and what do they want to happen with missing data? With |
|
Nice example. Your second version (the pdf) makes much more sense; the lines in the first plot (the png) can't be what anyone would want. |
|
A Github search isn't very enlightening. There are lots of copies of Matplotlib's This one plots masked data with flat shading, then there's a cell with a gouraud plot but unfortunately it's not executed so we can't see what the result is. This one uses Gouraud shading for data where the missing parts are filled with zeros, then flat shading for a masked array. I suspect they wouldn't like the interpolated grey for the hole at the North Pole. |
|
To make typical masking work as one might expect with G shading, maybe it would be necessary to special-case alpha==0? If alpha == 0 on any vertex of a triangle, set alpha to zero for the entire triangle? |
|
mplcairo gets you |
|
Thank you. Well, it looks like mplcairo is not the solution. It isn't working at all for gouraud shading in the first pdf example (at least as rendered by preview). In the second example, it has the same sort of difference between png and pdf as backend_pdf. |
|
The first example works for me? |
|
I can't do anything about that :/ |
|
I'm on High Sierra and I see but the exported png is better:It's difficult to say if Preview is wrong or if there's a problem in the pdf file. None of the pdf reader applications I have tried give any error messages for subtly malformed files, so developing a pdf writer is a lot of guesswork. In any case, this PR adds alpha channel support to the |
and name the new members like _foo_seq to make them obviously private and to conform to PEP8
The pytest version requirement has changed.
Follow the PEP8 naming convention in the new members.
9e04ce6 to
842a172
Compare
842a172 to
14b089f
Compare
efiring
left a comment
There was a problem hiding this comment.
I won't pretend to understand exactly what you have done, but the result looks great. Thank you!
| self.pageList = [] | ||
| self.fontObject = self.reserveObject('fonts') | ||
| self.alphaStateObject = self.reserveObject('extended graphics states') | ||
| self.extGStateObject = self.reserveObject('extended graphics states') |
There was a problem hiding this comment.
either keep the old name, or make the new name private, or at least document the change.
| def writeExtGSTates(self): | ||
| self.writeObject( | ||
| self.extGStateObject, | ||
| dict(itertools.chain( |
There was a problem hiding this comment.
(optionally)
dict([
*self.alphaStates.values(),
*self._soft_mask_states.values(),
])
And name its successor with an underline prefix.
anntzer
left a comment
There was a problem hiding this comment.
Anyone can merge after CI passes.











PR Summary
Suggestion for the request in #14327.
This is on top of
#14412(merged) and #14413.PR Checklist