plotly / plotly.py

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!
https://plotly.com/python/
MIT License
16.02k stars 2.54k forks source link

`plotly.graph_objects.Scatter` property `fillgradient` does not plot gradients with v5.22.0 in python #4649

Open JulienRim opened 2 months ago

JulienRim commented 2 months ago

Description

I am trying to use the fillgradient in a scatter plot with plotly. I copied the documentation code for its use, but on code execution, the gradient does not appear.

Operating system & Environment

Code used

import plotly.graph_objects as go

fig = go.Figure(
    [
        go.Scatter(
            x=[1, 2, 3, 4],
            y=[3, 4, 8, 3],
            fill=None,
            mode="lines",
            line_color="darkblue",
        ),
        go.Scatter(
            x=[1, 2, 3, 4],
            y=[1, 6, 2, 6],
            fill="tonexty",
            mode="lines",
            line_color="darkblue",
            fillgradient=dict(
                type="horizontal",
                colorscale=[(0.0, "darkblue"), (0.5, "royalblue"), (1.0, "cyan")],
            ),
        ),
    ]
)

fig.show()

Output in picture:

image
Coding-with-Adam commented 2 months ago

hi @JulienRim I'm getting this plot with Plotly 5.22.0. I'm using PyCharm and Firefox

image

JulienRim commented 2 months ago

@Coding-with-Adam Thanks for looking into this.

I took another look into this issue on my end, and I believe it to be related to using jupyter notebooks in VSCode. I cannot confirm if this is unique to MacOS or not.

I tried running this in a jupyter environment in a new terminal window: conda activate <env_with_plotly_5.22.0> jupyter notebook or jupyter lab

Running the same code as above yields the plot with fillgradient, as expected. When I went back to VSCode with the same jupyter notebook, it yielded the plot that I posted when I initially opened the ticket.

deeleeramone commented 5 days ago

Can confirm the same behavior as OP, Plotly V5.24.0 & Mac OS 14.6.1, gradient does not appear to work within VS Code Jupyter.