First, try parsing the dates as you read the data with pd.read_csv(). Currently, your code is treating those dates as strings because you didn’t tell it to do otherwise and it looks like most of the dates are being used as tick labels. I believe the example is done with the default date tick format for matplotlib so just parsing the date strings should solve the problem.
Second, you don’t have a fig because you never declared one because you are using the implicit plt.* interface to matplotlib and not the explicit one that typically uses fig and ax as variables. Consult the matplotlib quick start guide for details.
Hi @jimisin ,
The code you have posted seems to be correctly plotting the data and saving it as an image. You are using the plot method from matplotlib.pyplot to plot the data in the df dataframe, with the x-axis as the index (dates) and the y-axis as the “value” column. You are also setting the plot title, x-label, and y-label.
After the plot is created, you are using the savefig method from matplotlib.pyplot to save the plot as an image, in this case as a PNG image named “line_plot.png”.
Note that in the line fig.savefig('line_plot.png'), the variable fig is not defined in the code, so this line will raise a NameError. You can either define fig by assigning it to plt.figure(figsize=(12, 6)) before the savefig line, or remove the fig variable and simply use plt.savefig('line_plot.png').