-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Errors in rendering boundaries between filled paths and within a quadmesh #1188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If you start the code block with ```python you'll get some syntax highlighting. |
To me it seems like the pdf backend draws them correctly without addition edges however some viewers render these incorrectly and adds some white space. In the agg backend however even without edges there is an overlap between the paths visible only when alpha is less than 1. I guess this is an unrelated bug in the agg drawing code. It is correctly called with no edges. The pngs from the cairo backends are drawn without any overlap. However it does seem like this backend does not support alpha for imshow. I will open a separate issue for this. |
The pdf problem in evince is probably equivalent to this one |
Indeed the pdf problem in evince is fixed by applying the patch to poppler linked to in that bug report (0001-Align-fills-to-device-integer-coordinates.patch) so it seems like an aliasing problem. |
the colorbar. Resolve problems with white lines in colorbars. Not enabled by default. See matplotlib#1178 and matplotlib#1188
Add documentation of colorbar issue #1188 to colorbar documentation.
Did we decide that this is a viewer problem? If so, should this be closed as it requires an upstream fix? |
No there is another issue. The agg backend still renders the colorbar with overlap like the pdf did |
@jenshnielsen Thanks for clarifying. |
Is there still somebody looking into this one? I'm using matplotlib 1.4.2 (linux-x64) and still get these white stripes in the colorbar or contourf plots. I tested the pdf-files with various readers, i.e. okular (libpoppler), google-chrome, Adobe Reader/Acrobat XI (both Windows), and always see these stripes. The stripes almost disappear when I plot the same data twice (see the script below), but I consider this as a very bad workaround. The only fix that works consistently is to set Here is a script that shows how to reproduce and work around the white stripes for contourf plots and the colorbar. I hope it helps to debug and fix this problem.
|
As far as I understand this is a bug in the pdf renders which there is very little we can do about. If you draw 2 faces next to each other with no overlap a gab will often show due roundoff/snapping (Adobe seems to handle this better than most others in my tests). We can't draw them with an overlap in general since that would break partially transparent contours with alpha< 1. Try adding alpha=0.5 to all your contourf calls to see what I mean i.e Using |
Thanks for your quick answer! Alright, I see! So it really is related to the PDF renderer after all, this hasn't been clear to me from the discussion above. So the reason why if alpha is None:
edgecolor='face' I have no idea of the matplotlib internals, so I don't know where this should be best implemented. |
It might be possible to do something like that. I would have to think some more about this. In my original use case way back in 2012 this was only an issue for colorbars where the edges are straight. In this case Adobe seems to handle it correctly and the patch in the attached bug report fixed it for Evince on Ubuntu. It seems to be somewhat worse in your use case and still not really fixed. Briefly: Using preview on OSX: Using Adobe reader XI: |
I actually agree with you that for plots with alpha=1 this workaround just works "perfectly fine". So, I took a look at the source code, and for --- anaconda/lib/python2.7/site-packages/matplotlib/contour.py 2014-10-23 20:53:19.000000000 +0300
+++ tmp/contour.py 2015-02-03 16:45:46.267598199 +0200
@@ -942,10 +942,14 @@
paths = self._make_paths(segs, kinds)
# Default zorder taken from Collection
zorder = kwargs.get('zorder', 1)
+ if self.alpha is None:
+ edgecolors='face'
+ else
+ edgecolors='none'
col = mcoll.PathCollection(
paths,
antialiaseds=(self.antialiased,),
- edgecolors='none',
+ edgecolors=edgecolors,
alpha=self.alpha,
transform=self.get_transform(),
zorder=zorder) |
For --- anaconda/lib/python2.7/site-packages/matplotlib/axes/_axes.py 2015-02-03 16:35:25.849881579 +0200
+++ tmp/_axes.py 2015-02-03 18:13:43.624257733 +0200
@@ -5083,7 +5083,11 @@
vmax = kwargs.pop('vmax', None)
shading = kwargs.pop('shading', 'flat').lower()
antialiased = kwargs.pop('antialiased', False)
- kwargs.setdefault('edgecolors', 'None')
+ if alpha is None:
+ kwargs.setdefault('edgecolors', 'face')
+ kwargs.setdefault('linewidths', 0.0)
+ else
+ kwargs.setdefault('edgecolors', 'None')
allmatch = (shading == 'gouraud') Please note that all these suggestions are untested, and the colorbar would still need some additional work, since the function call to |
@dkxls Sorry your comments went unnoticed for so long. Can you put those changes in a PR? |
I'm uncomfortable with this hack; at the very least it needs to be checked with all backends to see what it actually does. Although the postscript standard is for linewidths of zero to be a device-dependent minimum, I think that in all backends we are treating linewidths of zero as "don't draw that line at all". If so, the hack will need some arbitrary small value for the linewidths. |
As far as the colorbar is concerned, the problem has been reduced by #4481, which is also a bit of a hack. |
It seems a bit annoying that this problem couldn't have been solved for almost a decade. It's blocking me from creating a phase plot with an amplitude overlay. I found no way to overcome it, neither of the suggestions here or in a related SE thread helped. All backends seem to suffer from this problem, and it propagates to the saved figure as well. If all plots using any colormap with transparency suffer from this bug, that seems like a huge issue to me - it makes this functionality utterly unusable. Matplotlib version: 3.3.2 Example code: import numpy as np
from matplotlib import pyplot as plt
from matplotlib.colors import LinearSegmentedColormap
# generate data
x = y = np.linspace(-2, 2, 300)
xx, yy = np.meshgrid(x, y)
ampl = np.exp(-(xx ** 2 + yy ** 2))
phase = (xx ** 2 - yy ** 2) * 3 * np.pi
data = ampl * np.exp(1j * phase)
# construct a simple b/w colormap with alpha
amp_cmap = {'red': [(0, 0, 0), (1, 1, 1)],
'green': [(0, 0, 0), (1, 1, 1)],
'blue': [(0, 0, 0), (1, 1, 1)],
'alpha': [(0, 1, 1), (1, 0, 0)]}
ampcm = LinearSegmentedColormap('alpha', amp_cmap)
# plot
fig, ax = plt.subplots()
ax.pcolormesh(xx, yy, np.angle(data), cmap='hsv')
ax.pcolormesh(xx, yy, np.abs(data), cmap=ampcm, linewidth=0, rasterized=True, edgecolor='face')
plt.show() |
@godot11 I cannot reproduce this on 3.4.2, so maybe upgrade? If you still have problems, please open a new issue with your explicit save command specified. |
Oops, seems it was indeed matplotlib. It slipped my eyes that I did a conda update wrongly before I posted. conda update log
|
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help! |
Re: github-actions, this is still present in 3.6.3. |
@gkatev Can you tell us exactly what is still present? This thread has many different issues. |
Hi, yes, sorry for being vague. Below is where the issue is exhibited for me -- please let me know if it's not relevant. This script reproduces the issue. Use this dataset: data.txt #!/usr/bin/python
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('data.txt', delim_whitespace=True)
df = df.pivot(index='core_1', columns='core_2', values='latency')
plt.pcolor(df, cmap='YlGnBu', rasterized=False)
plt.savefig('c2c.svg') The resulting svg file has unexpected white lines between the cells (viewing it in eog or in firefox). |
I know I assigned this ages ago, but I'm planning to work on it for 3.8. Though at the moment, I don't know that there is any way to fix SVG. |
I think this is really hard to fix. This is basically the same issue as with contours and arises because it is impossible to anti-alias properly: https://github.com/jklymak/contourfIssues. If you make your svg viewer not anti-alias this problem goes away. However, I really suggest rasterizing the pcolor. It can make for larger files, but pdf/svg viewers are pretty efficient at dealing with images in the svg. I actually think this should be closed as "can't fix", but maybe someone has a solution. |
The original post is about all formats, and at least Agg and PDF can be fixed. |
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help! |
This is the underlying problem raised in #1178.
It is illustrated by the test below; note that boundary anomalies are visible in all forms--agg on the screen, and pdf and svg displayed with a viewer--but in different places depending on the viewer and the size of the figure as rendered.
Note that the colorbar is rendered using pcolormesh, which has its own renderer with agg but otherwise is handled by draw_path_collection.
The text was updated successfully, but these errors were encountered: