I am trying to plot a simple multi-series line chart using the axes.plot() method whereby I need to pass the data to axes.plot() inside a for loop. The program is set up as follows:
def Plot(dict_inner):
df = pd.DataFrame.from_dict(dict_inner)
cases = df.columns.values.tolist()
fig, ax = plt.subplots()
x = df['Date']
for case in cases:
y = df[case]
ax.plot(x, y)
plt.legend()
plt.show()
This returns a list of errors for various matplotlib methods, ending with:
ValueError: view limit minimum -36502.7149864 is less than 1 and is an invalid Matplotlib date value. This often happens if you pass a non-datetime value to an axis that has datetime uni
ts
However, if the method is called outside the for loop as follows I am able to generate the plot:
def Plot(dict_inner):
df = pd.DataFrame.from_dict(dict_inner)
fig, ax = plt.subplots()
x = df['Date']
case_1 = '3xKd'
case_2 = '9xKd'
y1 = df[case_1]
y2 = df[case_2]
ax.plot(x, y1)
ax.plot(x, y2)
plt.legend()
plt.show()
I am new to Python and would appreciate any help. Thanks!

print(cases)to see that there are column names which you don't want to plot on the y axes.ax.plot(x, y)hold(True)