Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase thickness in a matplotlib annotation double sided arrow

Tags:

matplotlib

The width parameter works fine for a single sided arrow but I get an error when using a double sided arrow.

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 10, 1000)
plt.plot(x, np.sin(x));
plt.annotate('', xy=(3.2, 0), xycoords='data',
             xytext=(5.9, 0), textcoords='data',
             arrowprops=dict(facecolor='black', width=3))

This works fine and results in this plot: enter image description here

The code also works for a double sided arrow with no width specified:

plt.annotate('', xy=(3.2, 0), xycoords='data',
             xytext=(5.9, 0), textcoords='data',
             arrowprops=dict(facecolor='black', arrowstyle='<->'))

enter image description here

But for a double arrow with width:

plt.annotate('', xy=(3.2, 0), xycoords='data',
             xytext=(5.9, 0), textcoords='data',
             arrowprops=dict(facecolor='black', width=3, arrowstyle='<->'))

results in the matplotlib error: "AttributeError: Unknown property width"

like image 621
James Paul Mason Avatar asked Jan 30 '23 00:01

James Paul Mason


1 Answers

Try this:

arrowprops=dict(facecolor='black', lw=3, arrowstyle='<->')
like image 177
hadi noureddine Avatar answered Feb 02 '23 09:02

hadi noureddine