-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
inaccurate marker positioning in plot()
#7233
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
I wonder whether it is just a limitation on the ability of antialiasing to deliver a visual impression of sub-pixel accuracy. The steppiness is at the one-pixel level, but it doesn't look like simple pixel-snapping. |
Turning snapping off does not help that much. I wonder if this is related to the way we 'stamp' the markers? attn @mdboom |
import numpy
import scipy.stats
import matplotlib.pyplot as plt
plt.ion()
fig, ax = plt.subplots()
_xs = np.linspace(0, 30, 201);
ln, = ax.plot(_xs, scipy.stats.lognorm.pdf(_xs / 14, .472) / 14, ".") |
Yes, it's definitely related to how we stamp the markers. We don't do individual subpixel positioning for the markers. We could do that but it would be significantly slower (so should be a user-configurable option). |
I'm also suffering from this issue. See the attached script and image for an example of what happens to a grid of evenly spaced markers. This level of quality is simply not acceptable for professional use - it looks like something out of the 1980s, but this 2017, and subpixel positioning is no longer optional. |
Could you repost that example. The link appears to be broken. |
I would be curious if this is something that could be resolved with the Cairo rework? |
import math
import numpy
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
plt.style.use('dark_background')
fig = plt.figure()
ax = fig.add_subplot(111)
xv = []
yv = []
for y in range(10):
for x in range(10):
xv.append(x * 0.147)
yv.append(y * 0.147)
ax.set_xlim(0, 10)
ax.set_ylim(0, 10)
plt.scatter(xv, yv)
fig.savefig('grid.png') |
@WeatherGod It is indeed solved by mpl_cairo (in fact this was one of the original motivations for writing it). See second example at https://gitter.im/matplotlib/matplotlib?at=5963202789aea4761d81a829. (You even commenter right under it :-)) |
I hadn't noticed the marker positioning examples. I was more interested in
the text kerning at the time. That's great to know that the Cairo-based
backends can be a suitable work-around when they are available (I am open
to making them the default over AGG, but that might have to wait until
v3.0, and wider adoption of the newer C++ standards across compilers).
…On Thu, Aug 3, 2017 at 11:17 AM, Antony Lee ***@***.***> wrote:
@WeatherGod <https://github.com/weathergod> It is indeed solved by
mpl_cairo (in fact this was one of the original motivations for writing
it). See second example at https://gitter.im/matplotlib/matplotlib?at=
5963202789aea4761d81a829. (You even commenter right under it :-))
As a side note mpl_cairo also stamps the markers much faster (there's a
timing script in the examples).
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#7233 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AARy-G6TeHkczcdOOvjZokIwOXP9bqzLks5sUeSbgaJpZM4KRdrP>
.
|
I'm sure you can technically make it work in Agg... if someone actually understands the Agg rendering code paths (I gave up due to complete lack of documentation on Agg's side). The relevant part, which is at https://github.com/anntzer/mpl_cairo/blob/master/src/_mpl_cairo.cpp#L540 (cache preparation) and https://github.com/anntzer/mpl_cairo/blob/master/src/_mpl_cairo.cpp#L588 (marker stamping), should be fairly self explanatory if you know C++ -- I make a cache of renderered markers with various subpixel offsets (decided according to the path.simplify_theshold, because why not) and then the stamping loop just needs to pull out the right one each time. There's some discussion about using a recent g++ on a manylinux1 docker, which also involves statically linking a recent libstdc++ into a manylinux1 wheel, so that's apparently doable too... but tbh it's not very high on my priority list now. |
There is a nice visualization of this issue brought up in this Stackoverflow question. Running this with TkCairo shows the same issue as with TkAgg in the saved animation. Code for reproduction:
|
The difference is due to the fact that when saving an animation, we internally fallback on agg, because backend_cairo did not implement a way to dump the raw buffer. #10828 fixes that issue. You may also be interested in https://github.com/anntzer/mplcairo for a faster version... |
Yes. |
Is there really an action item for this? If not, I'll leave open but un-milestone. |
Yes, instead of generating 1 stamp and snapping to the nearest pixel, generate N and snap to nearest fraction of a pixel. |
not sure if related or said before, but either:
example:
|
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! |
mpl 1.5.3/2.0b4/master, no matplotlibrc
Note the slight inaccuracy in positioning of the markers at the positioning of the markers at the positions marked with the red circles, resulting in a "step-like" behavior (you may need to open the image in a larger viewer to notice it).
The data itself does not present this behavior, as can be checked just by zooming in these regions.
The text was updated successfully, but these errors were encountered: