DrawArrow: drawing arrows for matplotlib made easy

logo of a chart:drawarrow

DrawArrow is a library that allows to create arrows for your matplotlib charts with ease.

It was created by Joseph Barbier in order to create curved, straight, thin, large or bizarre arrows in matplotlib, in any color, width and style you like.

⏱ Quick start

Before using drawarrow you need to install it. This can easily be done with pip:


pip install drawarrow

# Load drawarrow and matplotlib
import matplotlib.pyplot as plt
from drawarrow import fig_arrow

fig, ax = plt.subplots()

ax.scatter(x=[1, 2, 3, 4, 5], y=[1, 2, 3, 4, 5], s=100)

fig_arrow(
  head_position=(0.5, 0.5),
  tail_position=(0.2, 0.7),
  color="red"
)

plt.show()

🔎 fig_arrow() function parameters→ see full doc

→ Description

The fig_arrow() function of drawarrow add an arrow on a given matplotlib figure. You can customize any of its properties such as its color, head/tail width, opacity...

→ Arguments

Draw an arrow on an axes

Matplotlib graphs have two main components:

  • the figure (the overall graph)
  • the axes (all the sub-graphs)

Learn more about it

The ax_arrow() function is designed to draw arrows on an axes. It means that it's using the same coordinate system as the plotted data.

Most basic arrow with drawarrow

Most basic arrow with drawarrow

import matplotlib.pyplot as plt
from drawarrow import ax_arrow

fig, ax = plt.subplots(figsize=(10,10))

ax.scatter(x=[1, 5, 10], y=[5, 12, 3], s=300)
ax_arrow(
   tail_position=(2, 8),
   head_position=(9.5, 3),
   ax=ax,
   color="green",
   tail_width=10,
   head_width=30,
   head_length=30,
   radius=0.4
)
plt.show()

Draw an arrow on a figure

Most basic arrow with drawarrow

Most basic arrow with drawarrow

The fig_arrow() function is designed to draw arrows on a figure: using the relative coordinate system. The position (0,0) means the bottom left and (1,1) the top right of the figure

import matplotlib.pyplot as plt
from drawarrow import fig_arrow

fig, ax = plt.subplots(figsize=(10,10))

ax.scatter(x=[1, 5, 10], y=[5, 12, 3], s=300)
fig_arrow(
   tail_position=(0.2, 0.8),
   head_position=(0.5, 0.3),
   fig=fig,
   color="red",
   tail_width=10,
   head_width=30,
   head_length=30,
   radius=-0.4
)
plt.show()

Customize the arrow

The arrow displayed is a FancyArrowPatch, a specialized matplotlib object for creating complex arrows. You can pass any additional arguments for this object to fig_arrow() and ax_arrow().


The example below demonstrates some of the most useful options.

Most basic arrow with drawarrow

Most basic arrow with drawarrow

import matplotlib.pyplot as plt
from drawarrow import fig_arrow

fig, ax = plt.subplots(figsize=(10,10))

ax.scatter(x=[1, 2, 3, 4, 5], y=[1, 2, 3.2, 4, 5], s=300)

fig_arrow(
   head_position=(0.48, 0.5),
   tail_position=(0.2, 0.7),
   fig=fig,
   facecolor="#003049",
   edgecolor="#d62828",
   linewidth=1,
   radius=1.2,
   alpha=0.9,
   hatch="O",
   tail_width=5,
   head_width=20,
   head_length=20,
   mutation_scale=4
)

plt.show()

Gallery of examples

Here are some examples of what you can do with drawarrow. Click on the images to see the code.

Going further

You might be interested in

Contact


👋 This document is a work by Yan Holtz. You can contribute on github, send me a feedback on twitter or subscribe to the newsletter to know when new examples are published! 🔥