Datum Matplotlib
Verfasst: Donnerstag 3. November 2022, 13:49
Ich möchte das Format der Datumsachse in einem Matplotlib Chart anpassen. Hier der DF
Chart:
Nun passe ich das Datumsformat an:
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m')) sorgt dafür, dass auf der x-Achse falsche Werte sind.
Könnt ihr helfen?
Code: Alles auswählen
period = pd.date_range('2017-01-01', periods=14, freq='m')
value = np.random.randint(5, size=14)
d = {'period':period,'value':value}
df = pd.DataFrame(d)
df['period'] = pd.to_datetime(df.period)
Code: Alles auswählen
fig,ax = plt.subplots(figsize=(14,10), dpi = 60)
df.plot(kind = 'line', x = 'period', y = 'value', ax = ax)
Code: Alles auswählen
fig,ax = plt.subplots(figsize=(14,10), dpi = 60)
df.plot(kind = 'line', x = 'period', y = 'value', ax = ax)
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m'))
Könnt ihr helfen?