Matplotlib Unknown property "headwidth" and "head_width"

I scratch my head on everything that would seem to be an easy problem. I am trying to just adjust the width of an arrow arrow in Matplotlib.

Here's the working code:

import numpy as np import matplotlib.pyplot as plt t = np.linspace(0,2*np.pi,500) y = np.sin(t) fig = plt.figure(figsize=(10,5)) ax = fig.add_subplot(111) ax.plot(t,y) ax.annotate('', xy=(1, -1), xytext=(2, 0), arrowprops=dict(arrowstyle='<->', facecolor='black')) 

Sine plot with double-headed arrow

And he depicts a beautiful double-headed arrow, as shown. Now that I want to change the bandwidth by doing:

 ax.annotate('', xy=(1, -1), xytext=(2, 0), arrowprops=dict(arrowstyle='<->', facecolor='black',headwidth=10)) 

or

 ax.annotate('', xy=(1, -1), xytext=(2, 0), arrowprops=dict(arrowstyle='<->', facecolor='black',head_width=10)) 

Error returned:

 AttributeError: Unknown property headwidth 

or

 AttributeError: Unknown property head_width 

It seems that I cannot find any resources through Google that solve this simple problem. Is there a way out?

Thank you very much for your time and attention!

+6
source share
1 answer

When you specify arrowstyle in your arrowprops pointer, you get, for example, FancyArrowPatch, not YAArrow, which accepts different keywords (but you probably knew that considering your attempt to use head_width ). What is not intuitive from the documentation is that when you specify an arrow style that has default settings for the chapter, etc., you change these specific settings in the arrow style line. This is the corresponding line from the documentation here (my attention):

The arrow style describes how the curly arrow will be drawn. This could be a string of available arrow names, with optional comma-delimited attributes, or one of ArrowStyle instances.

If you change the dictionary to the following, it will work:

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

Note that the head_width specification is in the decimal place after the style. Also: 10 is a pretty big number for that ... 0.5 could be better!

+10
source

Source: https://habr.com/ru/post/980024/


All Articles