Skip to content

ax_arrow

drawarrow.main.ax_arrow(tail_position, head_position, inflection_position=None, double_headed=False, fill_head=True, invert=False, radius=0, width=1, head_width=4, head_length=8, ax=None, shadow_style=None, **kwargs)

Draw an arrow on a Matplotlib axes using a FancyArrowPatch. The coordinate system used is that of a Matplotlib axes (data coordinates).

This function is very similar to what fig_arrow() does: only the change of coordinate system and the fig/ax arguments. You can find out more about how coordinate systems work in Matplotlib here.

Parameters

  • tail_position: Position of the tail of the arrow
  • head_position: Position of the head of the arrow
  • inflection_position: Current behavior may be unexpected and will probably change in the future. Optional position of the inflection point
  • double_headed: Whether the arrow has two heads or not
  • fill_head: Whether the arrowhead is filled or not
  • invert: Whether to invert or not the angle of the arrow (only used if radius!=0)
  • radius: Rounding radius of the edge. If inflection_position is not None, then it's the rounding radius at the inflection point
  • width: Width of the tail of the arrow
  • head_width: Head width of the tail of the arrow
  • head_length: Head length of the tail of the arrow
  • ax: The matplotlib axes to draw the arrow on. If None, uses the current axes
  • shadow_style: dictionary with arguments passed to matplotlib.patheffects.SimpleLineShadow:
    • offset: the offset between the arrow and its shadow
    • shadow_color: the color of the shadow
    • alpha: the opacity of the shadow
  • kwargs: any additional arguments passed to matplotlib.patches.FancyArrowPatch

Returns

  • FancyArrowPatch: The arrow patch object

Usage

import matplotlib.pyplot as plt
from drawarrow import ax_arrow

fig, ax = plt.subplots()

ax_arrow([0.1, 0.7], [0.1, 0.5], radius=0.3, color="red", ax=ax)

plt.show()


Examples

# mkdocs: render
import matplotlib.pyplot as plt
from drawarrow import ax_arrow

fig, ax = plt.subplots()

ax.scatter([1, 2, 3, 8, 6, 10], [2, 5, 3, 9, 2, 10])

ax_arrow(
    head_position=[6, 7],
    tail_position=[1, 1],
    radius=0.3,
    color="red",
    fill_head=False, # don't fill head
    ax=ax,
)
# mkdocs: render
import matplotlib.pyplot as plt
from drawarrow import ax_arrow

fig, ax = plt.subplots()

ax.scatter([1, 2, 3, 8, 6, 10], [2, 5, 3, 9, 2, 10])

ax_arrow(
    head_position=[6, 7],
    tail_position=[1, 1],
    radius=0.3,
    color="black",
    double_headed=True, # arrow with 2 heads
    ax=ax,
)
# mkdocs: render
import matplotlib.pyplot as plt
from drawarrow import ax_arrow

fig, ax = plt.subplots()

ax.scatter([1, 2, 3, 8, 6, 10], [2, 5, 3, 9, 2, 10])

ax_arrow(
    head_position=[6, 7],
    tail_position=[1, 1],
    radius=0.9, # bended arrow
    color="blue",
    ax=ax,
)
# mkdocs: render
import matplotlib.pyplot as plt
from drawarrow import ax_arrow

fig, ax = plt.subplots()

ax.scatter([1, 2, 3, 8, 6, 10], [2, 5, 3, 9, 2, 10])

ax_arrow(
    head_position=[6, 7],
    tail_position=[1, 1],
    head_length=20, # head length
    head_width=10, # head width
    color="#3a46a4",
    ax=ax,
)
# mkdocs: render
import matplotlib.pyplot as plt
from drawarrow import ax_arrow

fig, ax = plt.subplots()

ax.scatter([1, 2, 3, 8, 6, 10], [2, 5, 3, 9, 2, 10])

ax_arrow(
    head_position=[6, 7],
    tail_position=[1, 1],
    head_length=20, # head length
    head_width=10, # head width
    width=3,
    radius=0.1,
    shadow_style={"offset": (2.5, -4)},
    color="#3aa484",
    ax=ax,
)


Going further