6

Below figure shows the plot of which arrow head is very small... enter image description here

I tried below code, but it didnot work... it said " raise AttributeError('Unknown property %s' % k) AttributeError: Unknown property headwidth"...

xyfrom=[10,620]
xyto=[130,620]
ax.annotate("",xyfrom,xyto,arrowprops=dict(arrowstyle='<->',linewidth = 2,     headwidth=10,color = 'k'
))
ax.text((xyto[0]+xyfrom[0])/2-15,(xyto[1]+xyfrom[1])/2+10,"headwidth is too    small",fontsize=24)
user3737702
  • 591
  • 1
  • 10
  • 17

2 Answers2

13

I believe it's because you need to give your arrowstyle arguments inside a string. Try this:

 arrowprops=dict(arrowstyle='<->, head_width=10', facecolor='k')

, notice how this is a full string:

 '<->, head_width=10'

It's a really strange choice in matplotlib, one I really don't understand why should it be this way. In any case see if solves your problem.

armatita
  • 12,825
  • 8
  • 48
  • 49
  • 1
    Didn't work for me. I got `TypeError: __init__() got an unexpected keyword argument 'head_width'` with above solution. – con-f-use Apr 06 '17 at 15:15
  • @con-f-use I'm not sure but it's likely due to matplotlib version. This worked (I typically test before posting) but I found it a strange break of API rules for matplotlib even at the time. The [current documentation](http://matplotlib.org/users/annotations_intro.html) shows the `arrowprops` key table (search for it) where `headwidth` appears as a key for a dictionary. Try using outside the string. – armatita Apr 06 '17 at 15:41
  • Permutations of outside and inside the string as well as spelled "head_width" don't work. Matplotlib is always a fight... – con-f-use Apr 06 '17 at 15:52
  • @con-f-use Apparently it is `headwith` instead of `head_with` now... https://matplotlib.org/users/annotations_intro.html – n1000 May 23 '19 at 14:25
5

... since none of the above answers worked for me... here's my solution:

Use the "mutation_scale" argument! (see doc of FancyArrowPatch )

import matplotlib.pyplot as plt
f, ax = plt.subplots()

ax.scatter([1,2,3,4,5],[1,2,3,4,5])

ann = ax.annotate(rf'small head annotation',
                  xy=(2,2),  xycoords='data',
                  xytext=(.28, .5), textcoords='figure fraction',
                  size=10, va="center", ha="center",
                  bbox=dict(boxstyle="round4", fc="w"),
                  arrowprops=dict(arrowstyle="-|>",mutation_scale=25,
                                  connectionstyle="arc3,rad=-0.2", fc="w"))

ann2 = ax.annotate(rf'BIG head annotation',
                  xy=(2,2),  xycoords='data',
                  xytext=(.75, .15), textcoords='figure fraction',
                  size=10, va="center", ha="center",
                  bbox=dict(boxstyle="round4", fc="w"),
                  arrowprops=dict(arrowstyle="-|>",mutation_scale=50,
                                  connectionstyle="arc3,rad=-0.2", fc="w"))

 [

raphael
  • 2,159
  • 17
  • 20