How can I change the color range in ploty express scatter plots?
import plotly.express as px
...
fig = px.scatter(data,
x="X-coord",
y="Y-coord",
animation_frame="Timepoint",
color="Fraction",
hover_name="Compound",
size_max=10,
size='Fraction')
I want the colorbars to show a range from 0 to 1.
Most Plotly Express functions accept a color argument which automatically assigns data values to continuous color if the data is numeric. If the data contains strings, the color will automatically be considered discrete (also known as categorical or qualitative).
By default, Plotly Express will use the color scale from the active template 's layout.colorscales.sequential attribute, and the default active template is plotly which uses the Plasma color scale. You can choose any of the built-in color scales, however, or define your own.
This page is about using color to represent continuous data, but Plotly can also represent categorical values with color. This document explains the following four continuous-color-related concepts:
Color bars can be configured with attributes inside layout.coloraxis.colorbar or in places like marker.colorbar in go.Scatter traces or colorbar in go.Heatmap traces. color axes connect color scales, color ranges and color bars to a trace's data.
You can add range_color=(0,1)
to the keywords of px.scatter
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With