Issue With Matplotlib Rendering Dates, Image
I'm having an issue with Matplotlib v 3.1.3 from conda-forge with python 3.7. I have all of the dependencies required for Matplotlib. When I enter this code, which should work.
Solution 1:
It seems that the default setting in plot_date() is set to scatterplots (see (https://www.geeksforgeeks.org/matplotlib-pyplot-plot_date-in-python/) in the newer versions of matplotlib.
To achieve a continuous graph based on dates, you can define the interlining in the arguments plt.plot_date(x_value, y_value, '-')
.
This code works for me:
import matplotlib.pyplot as plt
import pandas as pd
df_train = pd.read_csv('test.csv', date_parser=True)
df_train.columns = ['date', 'col1', 'col2', 'col3', 'col4', 'col5', 'col6']
df_train['date'] = pd.to_datetime(df_train['date'])
df_train.set_index(['date'])
x_value = df_train['date']
y_value = df_train['col4']
plt.plot_date(x_value, y_value, '-')
plt.gcf().autofmt_xdate()
plt.show()
Output:
This functionality of not using the lineplot by default is indeed questionable given that the plot also automatically changes from scatterplot to lineplot when you just change the color: plt.plot_date(x_value, y_value, 'g')
.
This might just be a bug in the current versions of mpl.
Post a Comment for "Issue With Matplotlib Rendering Dates, Image"