I have a dataframe that associates each date with multiple values. The date range is from 02-02 to 04-30.
I have a dataframe with two columns -- 'Date' and 'Score'. The 'Date' entries are timestamps.
dem_data = {Timestamp('2020-02-02 22:27:00+0000', tz='UTC'): [0.5423],
Timestamp('2020-02-02 18:52:09+0000', tz='UTC'): [-0.1027],
Timestamp('2020-02-02 21:26:46+0000', tz='UTC'): [0.4939],
Timestamp('2020-02-03 18:35:43+0000', tz='UTC'): [0.8074],
Timestamp('2020-02-03 22:45:00+0000', tz='UTC'): [-0.7845],
Timestamp('2020-02-03 18:39:47+0000', tz='UTC'): [0.9081],
Timestamp('2020-02-04 05:43:06+0000', tz='UTC'): [0.8402],
Timestamp('2020-02-04 19:31:46+0000', tz='UTC'): [0.8316],
...}
I converted the Timestamp values to shortened string versions and made these values the indices for the dataframe.
Here's the code I wrote to plot the data:
fig_dims = (9, 6)
fig, ax = plt.subplots(figsize=fig_dims)
ax = sns.lineplot(x=dem_data.index, y='Score', data=dem_data, ax = ax)
ax.set_facecolor('white')
freq = int(10)
ax.set_xticklabels(concatenated.iloc[::freq].Date)
xtix = ax.get_xticks()
ax.set_xticks(xtix[::freq])
fig.autofmt_xdate()
plt.tight_layout()
plt.show()
And here's the resulting image.
A few things are strange about this.
- The x-axis is labeled as 'fake-date', the name of my index column, which includes shortened string versions of the timestamps in the 'dates' column. However, it displays the full timestamp, which I did not want.
- The x-axis only displays dates between 02-02 and 02-12.
How can I get the axis to display all dates (and in a way that is legible)?