[Question] No grouping in go.Scatter x axes

When plotting a go.Scatter with many values in the x axis, the points suddenly get grouped, so for the same visible point, multiple values are represented.

How can I represent all datapoints separately, independently of how big my x axis is?
Thank you!

1 Like

Find here a reproducible example:

import pandas as pd
import plotly.graph_objects as go


tmp = pd.read_csv('example.csv')

colors = {'A':'red', 'B':'green', 'C':'blue', 'D':'black'}
legenddrank = {'A':1, 'B':2, 'C':3, 'D':4}
plot = go.Figure()

# Create separately points and lines with go

added_statuses = set()
for _, row in tmp.iterrows():
    # Points
    showinlegend = row['label'] not in added_statuses # Do not repeat labels in legend, and then group them
    added_statuses.add(row['label'])
    hovertemplate = f"{row['label']} : {row['count']} / {row['total']}" # What to show when hovering
    plot.add_trace(
        go.Scatter(
            x = [row['time']],
            y = [row['count']],
            name = f"{row['label']} - {tmp[tmp['label'] == row['label']]['count'].sum()}",
            legendgroup=row['label'],
            showlegend=showinlegend,
            marker_color=colors[row['label']],
            hovertext=hovertemplate,
            hoverinfo='skip' if row['count'] == 0 else 'text', # Do not show in hover the elements with count = 0
            mode='lines+markers',
            ids=[row['label']],
            legendrank=legenddrank[row['label']]
        )
    )
for status in tmp['label'].unique().tolist():
    # Lines
    plot.add_trace(
        go.Scatter(
            x = tmp[tmp['label'] == status]['time'].tolist(),
            y = tmp[tmp['label'] == status]['count'].tolist(),
            mode='lines',
            marker_color=colors[status],
            showlegend=False,
            legendgroup=status,
            hovertext='',
            hoverinfo='skip'
        )
    )

plot.update_yaxes(title_text='Count')
plot.update_layout(legend={'title': 'Label - total'})
plot.update_xaxes(type='category', title_text='time', tickangle=45)
plot.update_layout(width = 1100, height = 600, showlegend=True, hovermode="x unified", plot_bgcolor='#EBEBEB')
plot.show()

Find the csv at this GitHub issue..