Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using plt.annotate() , how to adjust arrow color

I want to add some annotations and arrows to my plots using plt.annotate() and I am not sure how to change the arrow parameters.

import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({'weight': [10, 10, 20, 5, 10, 15]})

print(df)

Dummy Data:

   weight
0      10
1      10
2      20
3       5
4      10
5      15

Plot Line:

ax = df.plot(figsize=(8, 6))
ax.annotate("Maximum", xy=(2, 20), xytext=(2, 10),
            arrowprops=dict(arrowstyle="->"), color='red')

Test Line Chart

How do I change the arrow color and other parameters to also match the Text? In this case I changed the text color to red.

Thanks for the help!

like image 293
bkeesey Avatar asked Oct 24 '25 02:10

bkeesey


1 Answers

In arrowprops you should be able to set arrow color and other properties , something like this:

    arrowprops=dict(arrowstyle= '->',
                         color='red',
                         lw=3,
                         ls='--')
like image 117
José Manuel Vergara Álvarez Avatar answered Oct 25 '25 17:10

José Manuel Vergara Álvarez