Skip to content

px continuous color scale range adjustment when used in Dash callback #1917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DrGFreeman opened this issue Nov 22, 2019 · 2 comments
Closed

Comments

@DrGFreeman
Copy link

When updating the color parameter of a plotly_express scatter plot from a dcc.Dropdown within a Dash call back and returning the output of the scatter plot into the 'figure' property of a dcc.Graph, the range of the color scale (continuous) can increase if the range of the data passed to color increases but does not decrease automatically if the range of the data decreases.

The callback function is the following:

@app.callback(Output("graph", "figure"),
              [Input('x', 'value'),
               Input("y", "value"),
               Input("couleur", "value")])
def update_graph(x, y, couleur):
    fig = px.scatter(days, x=x, y=y, color=couleur, hover_data=days.columns)
    return fig 

The issue can be observed in this demo app: https://flask.urandom.xyz/boltev/

  1. Refresh the app to get the default parameter of the "Variable couleur" dropdown. The range of the color scale is -22 to 30.
  2. Change the "Variable couleur" dropdown to "fraction battery utilisée". This variable has a range of 0 to 1 but the color scale still shows -22 to 30 hence all the points have approximately the same color.
  3. Change the "Variable couleur" dropdown to "distance (km)". The colorscale changes to ~< 0 to ~420.
  4. Change the "Variable couleur" dropdown to "consommation (kWh/100km)". This variable has a range of 12 to 32 approx. Just as previously, the color scale keeps the larger range and the points show with a mostly uniform color.
  5. Clear the "Variable couleur" dropdown. The color scale disappears (expected).
  6. Set the "Variable couleur" dropdown back to "consommation (kWh/100km)". This time, the color scale matches the range of the data.

Playing a bit with the different variables and ranges, my conclusion is that the color scale min or max values will adjust only when the new min or max is outside the range or the previously rendered color scale. If a new variable with a range contained within the current range is passed, the color scale will not change at all.

The full code of the demo app is available at https://github.com/DamdlBT/BoltEV-Dash.

Package              Version  
-------------------- --------- 
dash                 1.4.0    
dash-core-components 1.3.0    
dash-html-components 1.0.1    
dash-renderer        1.1.1      
plotly               4.1.1    
plotly-express       0.4.1    

@emmanuelle, this is one of the two issues we discussed at the PyData meetup.

@emmanuelle
Copy link
Contributor

Hum, this one might be related to plotly/plotly.js#4337 and plotly/dash-core-components#702. Thanks for helping us investigate this problem!

@gvwilson
Copy link
Contributor

Hi - we are currently trying to tidy up Plotly's public repositories to help us focus our efforts on things that will help users most. Since this issue has been sitting for several years, I'm going to close it. If it's still a concern, we'd be grateful if you could open a new issue (with a short reproducible example if appropriate) so that we can add it to our backlog. Thanks for your help - @gvwilson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants