0

I am attempting to make a line graph showing home value change over the six months before a hurricane and the six months following a hurricane. I would like to add markers to each line with the value of the home at that time. I have the home value saved in a pandas DataFrame that contains the month and value for each hurricane. I have been trying to use the matplotlib ax.annotate function to do this, but have found no success.

import matplotlib.pyplot as plt

# Visualizing The Value Change of Homes Six Months Before and After Each Hurricane
  
# to set the plot size
fig = plt.figure()
  
# using plot method to plot values.
# in plot method we set the label and color of the curve.
charley_graph['value'].plot(label='Charley', color='orange', marker = 'o')
dennis_graph['value'].plot(label='Dennis')
matthew_graph['value'].plot(label='Matthew')
irma_graph['value'].plot(label='Irma')
michael_graph['value'].plot(label='Michael')
  
# adding title to the plot
plt.title('Top Tier Housing Value Change Six Months Before and After Each Hurricane')
  
# adding label to the x-axis
plt.xlabel('Months (0 = Hurricane Month)')

# adding label to the y-axis
plt.ylabel('House Value')

# adding legend to the curve
plt.legend();

#annotating
ax.annotate((charley_graph['value']), 'xy')

Which returns the graph, but with no annotations and this error.

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
jared
  • 4,165
  • 1
  • 8
  • 31
  • Is the error on the last line? You should share the whole error message in your question. Assuming it is, the first argument of `annotate` is the text while the second is the coordinates in a tuple. `"xy"` is not a tuple of coordinates. How many annotations are you adding? You will probably need to do this in a loop. – jared Jun 23 '23 at 21:29
  • Please create a minimal, reproducible, example. https://stackoverflow.com/help/minimal-reproducible-example It seems some of the problems are due to the use of Pandas and the specific data format you use. We cannot help you since we don't know the exact data you have used. – LudvigH Jun 26 '23 at 07:41

0 Answers0