Reputation: 141
I have a chart of a daily trend over time.
The year is not relevant here and I want to show only day and month. I know you can show year and month but that is not the case.
I tried to create a new variable called "Day_Month":
import datetime as dt
df['Day'] = df['date'].dt.day
df['Month'] = df['date'].dt.month
df['Day_Month'] = df['Day'].astype(str) + "-" +
but it's not possible to plot it as a string nor to convert it to date type.
eventually, I would like my chart to look like this:
Upvotes: 5
Views: 10545
Reputation: 141
The answer I found is:
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
plt.plot(date, price , label="Price")
ax.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d'))
Upvotes: 9