Skip to content

plotly express scatterplots not displaying correctly in jupyter #4154

Open
@OlovJ

Description

@OlovJ

I have an issue with larger scatterplots not displaying correctly. I am using jupyter on a Mac M1 and both using it from vs code and from jupyter-lab have the same issue (or I might be doing something wrong)

When displaying 1000 points it works as I expect but as soon as I get over 1000 points the x-values is not correct any more

import pandas as pd
import plotly
import plotly.express as px
import plotly.graph_objects as go
import random
import datetime

df = pd.DataFrame(columns=['metric', 'value', 'time'])
for i in range(1001):
    df = pd.concat([df, pd.DataFrame({'metric': random.choice(['a', 'b', 'c', 'd', 'e']), 
                                      'value': random.random()*20, 
                                      'time': datetime.datetime.now() + datetime.timedelta(seconds=random.randint(1, 300))}, index=[0])],
                                      ignore_index=True)
print(df.info())
print("Plotly version", plotly.__version__)
print("Pandas version", pd.__version__)
fig1 = px.scatter(df.head(1000), x="time", y="value", title="Durations", color='metric')
fig2 = px.scatter(df, x="time", y="value", title="Durations", color='metric')
fig1.show()
fig2.show()

Will have the output:

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1001 entries, 0 to 1000
Data columns (total 3 columns):
 #   Column  Non-Null Count  Dtype         
---  ------  --------------  -----         
 0   metric  1001 non-null   object        
 1   value   1001 non-null   float64       
 2   time    1001 non-null   datetime64[ns]
dtypes: datetime64[ns](1), float64(1), object(1)
memory usage: 23.6+ KB
None
Plotly version 5.14.1
Pandas version 2.0.0

and the plots
1000 points
image

and 1001 points
image

other information of value is that the hoover data is triggered in the correct place so when i hover empty space i get the correct popup
image

if i do it using go figures it works as expected

fig = go.Figure()
for metric, group in df.groupby("metric"):
    fig.add_trace(go.Scatter(x=group['time'], y=group['value'], mode='markers', name=metric))
fig.show()

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3backlogbugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions