0

How would I go about adding specific data points to a line chart through pandas/matplotlib?

This is what i have now:

And this is what i would like to do:

Cheers.

mhordflyer
  • 29
  • 5

2 Answers2

2

matplotlib.pyplot.annotate() can be used to annotate (add a string) to a particular point. For example:

import matplotlib.pyplot as plt
plt.scatter([1, 2, 3], [4, 5, 6])
plt.annotate("X", (1, 4))
plt.annotate("Z", (3, 6))
plt.show()
Ashok Arora
  • 539
  • 1
  • 6
  • 17
-1

you can address a specific data point on a chart using the index value. Remember the list is ordered from 0-X (i.e the first in your list = 0 and so on )

This function plots a blue square at point x,y where x is the data point first in the list =0 and y =0

fig.square(
  x_vals_ideal_projection[0], y_vals_ideal_projection[0], 
  fill_alpha=0, size=8, color='blue',
  legend_label="Projected Counts Burndown if wk 39 = 15 ")
Alex
  • 859
  • 10
  • 23
mhordflyer
  • 29
  • 5
  • this might solve your specific problem @khordi, but it doesn't answer the question of how to add text labels to data points in matplotlib very well. You have given a function call to a function `fig.square`, but what is this function? what is `fig` here? A matplotlib figure? `fig.square` is not a standard matplotlib function, so this is not useful to anyone else. – tmdavison Sep 20 '21 at 12:30
  • in fact looking at this function call more, perhaps you meant to ask about bokeh rather than matplotlib?! – tmdavison Sep 20 '21 at 12:34