Skip to content

margins does not handle bézier curves #7184

Closed

Description

@anntzer

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.

Activity

  1. added this to the milestone on Sep 26, 2016
  2. WeatherGod commented on Sep 26, 2016

    @WeatherGod
    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
    .

  3. efiring commented on Nov 14, 2016

    @efiring
    Member

    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.

  4. anntzer commented on Nov 14, 2016

    @anntzer
    ContributorAuthor

    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.

  5. modified the milestones: , on Nov 14, 2016
  6. efiring commented on Nov 14, 2016

    @efiring
    Member

    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.

  7. modified the milestones: v3.0, v3.1 on Aug 11, 2018
  8. modified the milestones: v3.1.0, v3.2.0 on Feb 25, 2019
  9. dopplershift commented on Apr 21, 2020

    @dopplershift
    Contributor

    Fixed by #16832.

  10. modified the milestones: needs sorting, v3.3.0 on Apr 21, 2020
  11. dstansby commented on Jan 2, 2021

    @dstansby
    Member

    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.

  12. dstansby commented on Jan 2, 2021

    @dstansby
    Member

    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.

  13. modified the milestones: v3.3.0, v3.6.0 on Aug 27, 2021
  14. modified the milestones: v3.6.0, v3.7.0 on Jul 8, 2022
  15. tacaswell commented on Feb 9, 2023

    @tacaswell
    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!

  16. dstansby commented on Feb 9, 2023

    @dstansby
    Member

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

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions