With matplotlib, how can I see the exact value of the cursor for date values at the bottom right of the interactive plot?
It seems, that this is dependent from the tick resolution:
the following code example has different tick resolution. As an effect, at the bottom right of the screenshots one time the cursor value is 2020
, one time it is 2020-09
.
I would like to have it as 2020-09-01
- so that it is with this resolution / granularity that the data has.
import datetime
import pandas as pd
import matplotlib
min_date = datetime.datetime.now().date()
max_date = min_date + datetime.timedelta(days=2*365)
date_range = [min_date + datetime.timedelta(days=x)
for x in range(0, (max_date - min_date).days)]
df = pd.DataFrame(date_range)
yRange = range(df.shape[0])
df["y"] = yRange
df.columns = ["x","y"]
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
plt.plot(df["x"], df["y"], "-o", markersize=2)
plt.show()
axes = plt.gca()
import matplotlib.ticker as ticker
tick_spacing = 50
axes.xaxis.set_major_locator(ticker.MultipleLocator(tick_spacing))
plt.rcParams["figure.dpi"] = 200
plt.xticks(rotation=20)
plt.grid()
plt.plot(df["x"], df["y"], "-o", markersize=2)
plt.show()