2

I have been trying to plot some time series graphs using the pandas dataframe plot function. I was trying to add markers at some arbitrary points on the plot to show anomalous points. The code I used :

df1 = pd.DataFrame({'Entropy Values' : MeanValues}, index=DateRange)
df1.plot(linestyle = '-')

enter image description here

I have a list of Dates on which I need to add markers.Such as:

Dates = ['15:45:00', '15:50:00', '15:55:00', '16:00:00']

I had a look at this link matplotlib: Set markers for individual points on a line. Does DF.plot have a similar functionality?

I really appreciate the help. Thanks!

Community
  • 1
  • 1
red_devil
  • 1,009
  • 2
  • 13
  • 23

1 Answers1

5

DataFrame.plot passes all keyword arguments it does not recognize to the matplotlib plotting method. To put markers at a few points in the plot you can use the markevery argument. Here is an example:

import pandas as pd

df = pd.DataFrame({'A': range(10), 'B': range(10)}).set_index('A')
df.plot(linestyle='-', markevery=[1, 5, 7, 8], marker='o', markerfacecolor='r')

Example plot

In your case, you would have to do something like

df1.plot(linestyle='-', markevery=Dates, marker='o', markerfacecolor='r')
Alicia Garcia-Raboso
  • 13,193
  • 1
  • 43
  • 48