Max Ghenis
Max Ghenis

Reputation: 15863

Set bounds on plotly express choropleth color scale

I'd like to set the bounds on a choropleth map in plotly express, e.g. such that this map goes from 0 to 5 instead of 1 to 100. Is this possible?

import pandas as pd
import plotly.express as px

df = pd.DataFrame({"state": ["CA", "OR"], "val": [1, 100]})

fig = px.choropleth(locations=df.state,
                    locationmode="USA-states",
                    color=df.val,
                    scope="usa")
fig.show()

(notebook) enter image description here

Upvotes: 2

Views: 1889

Answers (1)

Max Ghenis
Max Ghenis

Reputation: 15863

Use the range_color arg:

fig = px.choropleth(locations=df.state,
                    locationmode="USA-states",
                    color=df.val,
                    scope="usa",
                    range_color=(0,5))
fig.show()

enter image description here

Upvotes: 3

Related Questions