Allow tuning the shape of {L,R,D}Arrow tips. by anntzer · Pull Request #31198 · matplotlib/matplotlib

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).

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()