Load the example below. Because there's only 2 labels initially, the color scale takes this into account. If the slider is set all the way to max, the color scale will accomodate all 20 colors. However, when the slider is set back to 2, the scale is stuck at a 20 colors, and doesn't rescale to maximize contrast between 2.
Is this intentional?
Streamlit version 0.48.1
Plotly version 4.2.1
import plotly.express as px
import streamlit as st
import pandas as pd
import numpy as np
n_labels = st.slider(min_value=2, max_value=20, value=2, label="Number of labels")
data = pd.DataFrame(
{
"x": np.random.normal(0, 1, 20),
"y": np.random.normal(0, 1, 20),
"label": np.random.randint(1, n_labels + 1, 20),
}
)
fig = px.scatter(data, x="x", y="y", color="label")
st.write(fig)