1

In Pandas versions prior to 23.4 I could do this:

df.plot(x=df.DateTime, y=['var1', 'var2'])   

With df.DateTime as a datetime type. In v23.4 I get this error:

ValueError: x must be a label or position

I've been able to work around it based on advice in this thread: plot x-axis as date in matplotlib:

df = df.set_index(df.DateTime)
df.plot(y=['var1', 'var2'])   # i.e. don't specify x

My question: is this the right way to approach this with current Pandas and Matplotlib versions?

AlanD
  • 67
  • 6
  • 3
    Does `df.plot(x = "DateTime", y=['var1', 'var2'])` not work? If not, then you have the only working solution as of now. Pandas always changes a couple of things from version to version. Also you can of course use matplotlib `plt.plot(df.DateTime.values, df[['var1', 'var2']].values)`. – ImportanceOfBeingErnest Feb 25 '19 at 16:28
  • 1
    df.plot(x = "DateTime", y=['var1', 'var2']) does indeed work. Instead of x being provided as a Series, it needs to be the label of a column. My work around is not necessary. Thanks. – AlanD Feb 26 '19 at 22:36

0 Answers0