Announcing Dash Bio 1.0.0 🎉 : a one-stop-shop for bioinformatics and drug development visualizations.

Problem when making a multiline px.line() plot with time axis

I’m making a dashboard for environmental monitoring.
Essentially the task consists is:
(on the y axis) plotting the concentrations of a given pollutant and for (possibly multiple) monitoring stations,
(on the x axis) the date when this concentration occurred.

For some reason when plotting for more than one station the x-axis repeats itself leading to broken plot.
By repeat itslef I mean, once it reache the end of the month, add some other dates at the end.

As you can see from the image the 21 of February reappears.

This is the code that I use for generating the plot.

def plot_pollutant_multi_stations_date(start_date, end_date, pollutant, poll_df, stations,
        limits_df, title):
    poll_df = poll_df.sort_values(by='Date')
    poll_df = poll_df[(poll_df['Date']>=start_date) & (poll_df['Date']<=end_date) & 
    #poll_df = poll_df[poll_df['Month'] == month]
    poll_df = poll_df.sort_values(['To Date']).reset_index(drop=True)
    fig = px.line(poll_df, x = 'To Date', y = pollutant, color = 'Station')
    #fig.layout.xaxis.tickmode = 'array'
    #fig.layout.xaxis.ticktext = poll_df['Date']
    fig.layout.xaxis.nticks = 10
    x_0 = poll_df['To Date'].min()
    x_f = poll_df['To Date'].max()
    #add Limit
    lim = limits_df[limits_df['Pollutant'] == pollutant]['Level']
    fig.update_layout(title=title + ' for ' + pollutant)
    if not lim.empty:
        lim = lim.to_numpy()[0]
        fig.add_hline(y=lim, line_color='red', annotation_text='Limit')

    return fig

This happens for datetimes when one of the stations doesn’t have a datatip.
Any ideas on how to handle this?

Thank you!

I fixed it by changing data to pd.to_datetime and is working now.