5

I want to change the head of an arrow in an annotation (matplotlib), but it doesn't work when used together with other properties, like shrink. It seems to change the type of object created, by looking at the parameters set.


Example

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.plot(xx,yy)
ax.set_ylim([-2,2])

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

enter image description here


Problem

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

Community
  • 1
  • 1
Luis
  • 3,327
  • 6
  • 35
  • 62

1 Answers1

0

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.

Julien Spronck
  • 15,069
  • 4
  • 47
  • 55