Skip to content

arrow_spines

drawarrow.arrow_spines.arrow_spines(bottom='toright', left='totop', right=None, top=None, ax=None, **arrow_style)

Replace matplotlib spines with arrows instead. By default it adds an arrow at the bottom spine (to the right) and an arrow at the left spine (to the top), but it can customized. See examples below.

Parameters:

  • bottom: direction of the arrow (either 'toright' or 'toleft'). No arrow if None
  • top: direction of the arrow (either 'toright' or 'toleft'). No arrow if None (default)
  • left: direction of the arrow (either 'totop' or 'tobottom'). No arrow if None
  • right: direction of the arrow (either 'totop' or 'tobottom'). No arrow if None (default)
  • ax: The matplotlib axes to draw the arrow on. If None, uses the current axes
  • arrow_style: any additional arguments passed to ax_arrow()

Returns:

  • Axes: the matplotlib axes

Usage

import matplotlib.pyplot as plt
from drawarrow import arrow_spines

fig, ax = plt.subplots()
arrow_spines(ax=ax, color="red")
plt.show()


Examples

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

fig, ax = plt.subplots()

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

arrow_spines(ax=ax, color="red")
# mkdocs: render
import matplotlib.pyplot as plt
from drawarrow import arrow_spines

fig, ax = plt.subplots()

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

arrow_spines(
   right="totop",
   bottom="toleft",
   left=None, # remove left spine
   ax=ax,
   color="red",
)
# mkdocs: render
import matplotlib.pyplot as plt
from drawarrow import arrow_spines

fig, ax = plt.subplots()

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

arrow_spines(
   ax=ax,
   color="#7b2e8e", # purple
   width=3,
   head_length=15,
   head_width=10,
)

ax.tick_params(size=0, pad=15) # remove ticks and add padding


Going further