X Tutup
Skip to content

Allow tuning the shape of {L,R,D}Arrow tips.#31198

Merged
QuLogic merged 3 commits intomatplotlib:mainfrom
anntzer:roadsign
Mar 27, 2026
Merged

Allow tuning the shape of {L,R,D}Arrow tips.#31198
QuLogic merged 3 commits intomatplotlib:mainfrom
anntzer:roadsign

Conversation

@anntzer
Copy link
Copy Markdown
Contributor

@anntzer anntzer commented Feb 25, 2026

PR summary

Implements the "road sign" arrows requested at #24618 (closes #24618). The implementation is the one suggested at #29998 (comment) (with some tweaks, especially in the obtuse reverse arrow case), so that the shape varies continuously with the parameters. To acknowledge the original PR authors I've squashed their commits and kept them as respective authors of a docs commit (extracted from #24744) and a test commit (directly taken from #29998, although the baseline image is actually different).

@QuLogic's interactive test script is reproduced below for convenience:

import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from matplotlib.widgets import Slider

fig, ax = plt.subplots(3, 1, height_ratios=[4, 1, 1])

texts = []
for i, arrow in enumerate(['larrow', 'rarrow', 'darrow']):
    texts.append(
        ax[0].text(0.5, 0.3*i + 0.2, 'Arrow', ha='center', size=16,
                   bbox=dict(boxstyle=f"{arrow}, pad=0.3, head_angle=150")))


def update_head_angle(value):
    for t in texts:
        t.get_bbox_patch().get_boxstyle().head_angle = value
    fig.canvas.draw_idle()


def update_head_width(value):
    for t in texts:
        t.get_bbox_patch().get_boxstyle().head_width = value
    fig.canvas.draw_idle


angle_slider = Slider(ax[1], 'Angle', 0, 360, valinit=150, closedmin=False)
angle_slider.on_changed(update_head_angle)

width_slider = Slider(ax[2], 'Width', 0, 3, valinit=1.5)
width_slider.on_changed(update_head_width)

plt.show()

PR checklist

@github-actions github-actions bot added the Documentation: user guide files in galleries/users_explain or doc/users label Feb 25, 2026
@anntzer anntzer force-pushed the roadsign branch 2 times, most recently from f0a6cf3 to d65b419 Compare February 25, 2026 10:35
The new *head_width* and *head_angle* parameters to
`.BoxStyle.LArrow`, `.BoxStyle.RArrow` and `.BoxStyle.DArrow` allow for adjustment
of the size and aspect ratio of the arrow heads used.

Copy link
Copy Markdown
Member

@timhoffm timhoffm Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To give a consistent appearance across all parameter values, the
default head position (where the head starts relative to text) is
slightly changed compared to the previous hard-coded position.

Copy link
Copy Markdown
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could have a more in-depth example on how the parameters work. The what's new entry is the only visualization and it's not discoverable from the Arrow docs.

But that can also come later.

@anntzer
Copy link
Copy Markdown
Contributor Author

anntzer commented Feb 26, 2026

thanks, fixed. I'll skip on the extra docs :)

@QuLogic
Copy link
Copy Markdown
Member

QuLogic commented Mar 27, 2026

You'll need to rebase to get docs to run properly (also CI has been fixed.)

anntzer and others added 3 commits March 27, 2026 10:49
@anntzer
Copy link
Copy Markdown
Contributor Author

anntzer commented Mar 27, 2026

rebased

@QuLogic QuLogic merged commit 49fd492 into matplotlib:main Mar 27, 2026
39 of 41 checks passed
@anntzer anntzer deleted the roadsign branch March 27, 2026 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation: user guide files in galleries/users_explain or doc/users topic: annotation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENH]: "Road sign" boxstyle/annotation

5 participants

X Tutup