I want to plot this data frame, with dates on the x-axes and values on the y-axes.
f_index=pd.date_range(start='1/1/2020', end='1/12/2020')
f_data=np.arange(0,len(f_index))
df=pd.DataFrame(data=f_data, index=f_index,columns=['Example'])
On the x ticks, I want to show only two dates like 2020,3,2
, and 2020,6,8
because are the relevant ones.
So I was thinking about something like that:
x1=(pd.Timestamp(2020,3,2)-f_index[0]).days
x2=(pd.Timestamp(2020,6,8)-f_index[0]).days
xx=[x1,x2]
fig2, ax2= plt.subplots(figsize=(6,4),
facecolor='white', dpi=300)
ax2.plot(df.index,df.Example)
#ax2.set_xticks(xx)
#ax2.set_xlabel(xx)
plt.show()
but it doesn't work.
I tried different methods and read different questions, but I did not find one with my specific answer.
This is what can I get at the moment for simplicity I rotated the dates with ax2.tick_params(axis='x',rotation=90)
but is not in the code above.
This is what I would like to get
For me is important to understand how dates work because then I want to plot two straight lines in correspondence of the specific dates, something like this.