Skip to content

margins does not handle bézier curves #7184

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

Closed
anntzer opened this issue Sep 26, 2016 · 9 comments
Closed

margins does not handle bézier curves #7184

anntzer opened this issue Sep 26, 2016 · 9 comments

Comments

@anntzer
Copy link
Contributor

anntzer commented Sep 26, 2016

2.0b4, example modified from http://matplotlib.org/users/path_tutorial.html#bezier-example

import matplotlib.pyplot as plt
from matplotlib.path import Path
import matplotlib.patches as patches

verts = [
    (0., 0.),  # P0
    (0.2, 1.), # P1
    (1., 0.8), # P2
    (0.8, 0.), # P3
    ]

codes = [Path.MOVETO,
         Path.CURVE4,
         Path.CURVE4,
         Path.CURVE4,
         ]

path = Path(verts, codes)

fig, axs = plt.subplots(2)

patch = patches.PathPatch(path, facecolor='none', lw=2)
axs[0].add_patch(patch)
xs, ys = zip(*verts)
axs[0].plot(xs, ys, 'x--', lw=2, color='black', ms=10)

patch = patches.PathPatch(path, facecolor='none', lw=2)
axs[1].add_patch(patch)

plt.show()

figure_1

Note how the bottom axes have their limits set as if using the positions of the bézier control points (on the unit square), with no margins.

@tacaswell tacaswell added this to the 2.0 (style change major release) milestone Sep 26, 2016
@WeatherGod
Copy link
Member

This is similar to my comments back during the SciPy conference about how
hit-testing is done on the original list of coordinates rather than on the
output list. Other operations like this is also done on the original data
rather than the generated coordinates.

This is a bit trickier, though because the margins are supposed to be about
the datapoints, not the lines. Usually, they are one and the same, but that
is not the case for bezier curves.

On Mon, Sep 26, 2016 at 4:56 PM, Antony Lee notifications@github.com
wrote:

2.0b4, example modified from http://matplotlib.org/users/
path_tutorial.html#bezier-example

import matplotlib.pyplot as plt
from matplotlib.path import Path
import matplotlib.patches as patches

verts = [
(0., 0.), # P0
(0.2, 1.), # P1
(1., 0.8), # P2
(0.8, 0.), # P3
]

codes = [Path.MOVETO,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
]

path = Path(verts, codes)

fig, axs = plt.subplots(2)

patch = patches.PathPatch(path, facecolor='none', lw=2)
axs[0].add_patch(patch)
xs, ys = zip(*verts)
axs[0].plot(xs, ys, 'x--', lw=2, color='black', ms=10)

patch = patches.PathPatch(path, facecolor='none', lw=2)
axs[1].add_patch(patch)

plt.show()

[image: figure_1]
https://cloud.githubusercontent.com/assets/1322974/18851432/c9de4e8e-83f0-11e6-9e61-2d72101b0f81.png

Note how the bottom axes have their limits set as if using the positions
of the bézier control points (on the unit square), with no margins.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#7184, or mute the thread
https://github.com/notifications/unsubscribe-auth/AARy-AGRMMMrZBIpnpJ2Cil3GEtG1zRzks5quDGOgaJpZM4KG_E6
.

@efiring
Copy link
Member

efiring commented Nov 14, 2016

I would classify this as "won't fix". Autoscaling is already enough of a mess without trying to take Bezier curves into account. It's not supposed to be perfect, and able to handle every possible situation; it is supposed to provide a decent first-try plot most of the time.

@anntzer
Copy link
Contributor Author

anntzer commented Nov 14, 2016

I certainly don't mind milestoning this as 3.0 (as in "far, far future") but I'm don't think the problem is unresolvable.

@efiring efiring modified the milestones: 3.0 (future), 2.0 (style change major release) Nov 14, 2016
@efiring
Copy link
Member

efiring commented Nov 14, 2016

It's not a question of whether it can be solved, but of whether it is worth the effort and the added complexity. We need to set priorities.

@dopplershift
Copy link
Contributor

Fixed by #16832.

@dstansby
Copy link
Member

dstansby commented Jan 2, 2021

I'm not sure why this was closed; on the current master branch I can reproduce the test case in the original issue, so I don't think this has been fixed yet.

@dstansby dstansby reopened this Jan 2, 2021
@dstansby
Copy link
Member

dstansby commented Jan 2, 2021

Also worth noting that one needs to manually autoscale the Axes after adding a patch to see the autoscale behaviour, which isn't currently present in the example at the top. Adding axs[1].autoscale() just before plt.show() works, and shows that the control points are still included in the auto scaling.

@QuLogic QuLogic modified the milestones: v3.3.0, v3.6.0 Aug 27, 2021
@QuLogic QuLogic modified the milestones: v3.6.0, v3.7.0 Jul 8, 2022
@tacaswell
Copy link
Member

Adding axs[1].autoscale() just before plt.show() works, and shows that the control points are still included in the auto scaling.

I think this means it is fixed as adding the auto scaling line gives:

so

which is scaling to the curve and not to the control points. If add_patch should autoscale automatically is a different question!

@dstansby
Copy link
Member

dstansby commented Feb 9, 2023

I suspect (but haven't checked) that #19216 fixed this

@tacaswell tacaswell modified the milestones: v3.7.0, v3.4.0 Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants