Luis Luis - 6 months ago 42
Python Question

How to change the arrow head style in matplotlib annotate?

I want to change the head of an arrow in an annotation (

), but it doesn't work when used together with other properties, like
. It seems to change the type of object created, by looking at the parameters set.


The following code shows two types of annotation arrows.

import matplotlib.pyplot as plt

import numpy as np

xx = np.linspace(0,8)
yy = np.sin(xx)
fig, ax = plt.subplots(1,1, figsize=(8,5))

ax.annotate( 'local\nmax', xy=(np.pi/2, 1), xytext=(1,1.5), ha='center', \
ax.annotate( 'local\nmin', xy=(np.pi*3/2, -1), xytext=(5,0), ha='center', \

enter image description here


I tried to set the arrow type together with the other properties in the first annotation like this:

ax.annotate( 'other\nmax', xy=(np.pi*5/2, 1), xytext=(7,1.5), ha='center', \
arrowprops={'arrowstyle':'->', 'shrink':0.05})

However, that line throws an error:

AttributeError: Unknown property shrink

Why does it not work?

How do I change the arrow head style of an annotation?

Related question

I am using:

python: 3.4.3 + numpy: 1.11.0 + matplotlib: 1.5.1


From the matplotlib documentation, "if the dictionary has a key arrowstyle, a FancyArrowPatch instance is created with the given dictionary and is drawn. Otherwise, a YAArrow patch instance is created and drawn."

As you can see in the same link, shrink is a valid key for YAArrow but not for FancyArrowPatch.