Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the head size of the double head annotate in matplotlib?

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)
like image 930
user3737702 Avatar asked Mar 22 '16 07:03

user3737702


2 Answers

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.

like image 62
armatita Avatar answered Nov 14 '22 23:11

armatita


... 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"))

 [

like image 34
raphael Avatar answered Nov 14 '22 22:11

raphael