Даты по оси X (plotly, python)

Строю график наблюдений за температурой за 8 лет, CSV беру здесь (Архив погоды на метеостанции): https://rp5.ru/ Столкнулась с проблемой отображения дат по оси X, пока реализовала с помощью .dayofyear:

import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
import matplotlib.dates as mdates
import cufflinks
cufflinks.go_offline()
cufflinks.set_config_file(world_readable=True, theme='pearl', offline=True)
import plotly.graph_objs as go
import seaborn as sns
import plotly.io as pio
pio.templates

file = "00000.csv.gz"
df = pd.read_csv(file, sep=';', skipinitialspace=True, quotechar='"', compression='gzip', 
error_bad_lines=False,
             skiprows=[0, 1, 2, 3, 4, 5, 6], header=None)
df.drop([3, 4, 8, 9, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29], 
axis='columns', inplace=True)
df.set_axis(['date', 'temp', 'prec', 'wetness', 'wind', 's_wind', 'col_cloud', 'n_weather'], 
axis='columns', inplace=True)
# отделяем колонку "время" из столбца "дата" в отдельный столбец
df[['date', 'time']] = df['date'].str.split(' ', expand=True)

# группируем по дате и вычисляем среднюю температуру за каждый день

dt0 = df.groupby(['date'])['temp'].mean()

# из series в dataframe
dt1 = pd.DataFrame(data=dt0.index, columns=['date'])


dt2 = pd.DataFrame(data=dt0.values, columns=['temp'])
dm = pd.merge(dt1, dt2, left_index=True, right_index=True).sort_values(by = 'date', ascending = True)
dm['date'] = pd.to_datetime(dm['date'], format='%d.%m.%Y')
# индексный столбец
dm = dm.set_index(dm.columns[0]).sort_index()
# график
fig = go.Figure()
fig.update_yaxes(zeroline=True, zerolinewidth=2, zerolinecolor='LightPink')
for years in dm.index.year.unique():
    a = dm[dm.index.year == years].index.date
    x = dm[dm.index.year == years].index.dayofyear
    y = dm[dm.index.year == years]['temp']
    fig.add_trace(go.Scatter(x=x, y=y,
                        mode='lines+markers',
                        name=years,
                        text=a))
    fig.update_traces(hovertemplate=None)
    fig.update_layout(
        hovermode="x unified")
fig.show()

В итоге график строится, но по X идут номера дней года. Хотелось бы, чтобы по оси X были даты без года, например 01.01, 01.02 и так далее. Как это можно сделать?


Ответы (0 шт):