Skip to content

Various issues with miter limits #9830

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

Open
anntzer opened this issue Nov 22, 2017 · 5 comments
Open

Various issues with miter limits #9830

anntzer opened this issue Nov 22, 2017 · 5 comments
Labels
keep Items to be ignored by the “Stale” Github Action

Comments

@anntzer
Copy link
Contributor

anntzer commented Nov 22, 2017

Noticed this a while ago (while implementing mplcairo) but prompted to report due to #9829:

from matplotlib import pyplot as plt, ticker

fig, axs = plt.subplots(4, 4)
for i, ax in enumerate(axs.flat):
    ax.xaxis.set_major_locator(ticker.NullLocator())
    ax.yaxis.set_major_locator(ticker.NullLocator())
    ax.plot([-1, 0, 1], [0, 1, 0], lw=i, solid_joinstyle="miter")
    ax.set(xlim=(-15, 15), ylim=(0, 3))

fig.savefig("/tmp/test.png")
fig.savefig("/tmp/test.svg")
fig.savefig("/tmp/test.pdf")

plt.show()

pdf appears to respect the miter ("pointed") joinstyle (funnily this appears to behave in the opposite manner as #9829):
test-pdf
svg appears to ignore it:
test-svg
agg changes its mind half-way:
test

The behavior of agg is almost certainly due to a misunderstanding in how the miter limit is set. See https://www.w3schools.com/tags/canvas_miterlimit.asp and https://www.cairographics.org/manual/cairo-cairo-t.html#cairo-set-miter-limit for the definition of the miter limit. Note that the two definitions differ: html defines it in absolute lengths whereas cairo defines it relative to the linewidth.

backend_agg.h has the line (multiple times)

stroke.miter_limit(points_to_pixels(gc.linewidth));

which suggest that the author thought miter_limit takes an absolute miter limit, but in fact a relative miter limit should have been given (how do I know this? because I can reproduce the same behavior with mplcairo with the same setting, and cairo clearly documents that it uses a relative miter limit :-)).

So the current implementation ends up switching from miter join to bevel join at an angle that depends on the linewidth, eek.


NOTE: when this is fixed, remember to regen the logo per #14939 (which also showcases the issue).

@brunobeltran
Copy link
Contributor

there are two issues here:

  1. The miter_limit is not explicitly set by matplotlib anywhere. Therefore, each backend will end up effectively utilizing whatever the target is (e.g. 4 for SVG, 10 for PostScript and PDF, etc.)
  2. Agg in particular appears to still treat miter limits incorrectly (I can reproduce this issue on 3.1.3).

So to really deal with this issue, it looks like we'd have to actually add a new rcParam (miterlimit), and have each of the backends respect it (including a simple change in _backend_agg.h to force the Agg backend to treat miter limit as relative, as that is the standard everywhere else).

This bug seems reasonably low priority and high effort? But if I want to correctly handle miter limits in #16607, I would need to add this new rcParam first...

@anntzer
Copy link
Contributor Author

anntzer commented Mar 12, 2020

I agree that this is pretty high effort/low priority (though see #14939)...

@github-actions
Copy link

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!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Apr 25, 2023
@anntzer
Copy link
Contributor Author

anntzer commented Apr 25, 2023

Still true, still low priority.

@github-actions github-actions bot removed the status: inactive Marked by the “Stale” Github Action label Apr 26, 2023
Copy link

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!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Jun 12, 2024
@anntzer anntzer added keep Items to be ignored by the “Stale” Github Action and removed status: inactive Marked by the “Stale” Github Action labels Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep Items to be ignored by the “Stale” Github Action
Projects
None yet
Development

No branches or pull requests

2 participants