plotly / plotly/plotly.py

Scattergl not drawing line with np.inf but only when in pd.Dataframe

Open
#5,228 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P2
Dominant language
Python
Stars
18.8k
Forks
2.8k
Avg merge
16h 26m
Merged PRs (30d)
21

Description

Hello,

I’m having a strange issue where a graph_objects Figure with Scatergl is not drawing anything if there is an np.inf in the series, but only if the data is coming from a Pandas Dataframe. The below code shows an example of the issue (See 3rd figure). This issue appears with 6.0.0 install in python.

import plotly.express as px
import plotly.graph_objects as go
import numpy as np
import pandas as pd

# Create a DataFrame with np.inf in a column
df = pd.DataFrame({
    'x': [0, 1, 2, 3, 4],
    'y': [0, 1, 4, 9, np.inf],
})

# Create a line plot  (Things are OK)
fig = px.line(data_frame=df, x='x', y='y', title='Looks OK')
fig.show()


# Create a line plot w/ Scatter  (Things are OK)
fig = go.Figure()
fig.add_trace(go.Scatter(
    x=df['x'],
    y=df['y'],
    mode='lines',
))
fig.update_layout(title=dict(text="Looks OK"),)
fig.show()


# Create a line plot w/ Scattergl  (Nothing shown on figure...)
fig = go.Figure()
fig.add_trace(go.Scattergl(
    x=df['x'],
    y=df['y'],
    mode='lines',
))
fig.update_layout(title=dict(text="Nothing displayed..."),)
fig.show()


# Create a line plot w/ Scattergl  (This is ok.... to_list fixes something?)
fig = go.Figure()
fig.add_trace(go.Scattergl(
    x=df['x'].to_list(),
    y=df['y'].to_list(),
    mode='lines',
))
fig.update_layout(title=dict(text="Looks OK"),)
fig.show()

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied Python reproduction with plotly 6.0.0 and compare the Scatter, Scattergl, and list-converted inputs. The issue is done when Scattergl renders the line from Pandas Series containing np.inf consistently with the other examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
pandas, python
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.