Hey all, I’ve been trying to figure out how to create a subplot that shows both a line plot and a scatter plot of different data, but the same categories. The problem I’m currently encountering is that the legend color doesn’t correspond to the scatter plot colors. I’m trying to figure out how to share the colors and legend names between the subplots.
To share legend, I’m currently using the approach in Legends in Python
If there’s an entirely better approach to doing a line/scatter subplot, please let me know. I couldn’t figure out how to do this with plotly.express
Thanks for the suggestion. The way my data is structured, I don’t know how many categories I’ll have, so hard-coding colors feels tedious. Is there a plotly way to construct a discrete color sequence from a built-in color scale?
For example, Is there a way to do something like
speakers = set(num_speakers)
color_sequence = discrete_equence('viridis', len(speakers))
for n_speakers, color in zip(speakers, color_sequence):
...
Thanks @AIMPED. Here’s a snippet with what I ended up with. I slightly simplified the y variable by using np.linspace instead of np.arange. Also, sample_colorscale takes a min, and max argument, so passing y, and max=DATAPOINTS in your example would yield the same result.