Legend bug going between continuous and discrete coloring

I generate a new figure for my plots depending on a radio button selection. One of the options shows a discretely colored plot that I set in the figure with color_discrete_map={β€˜Yes’: β€˜#EFF814’, β€˜No’: β€˜#13078A’}.

When I switch to one of my continuous colored map options (e.g. color_continuous_scale=β€˜Hot_R’) and then back to my discrete map selection, the coloring is showing the gradient from the previous plot.


This only happens in the case where the map is only plotting 1 discrete value, so all β€œYes” or all "No. If both β€œYes” and β€œNo” values are present in one of the maps then the coloring gets set correctly. When you download the graph it actually downloads with the legend colored correctly, it just isn’t displaying it right in the browser.

The figures are generated by different functions. I have tried setting fig to None before generating. I don’t know if there is some better way to β€œclear” the figure first or specify the discrete coloring if there’s only 1 value showing. It works fine if I have not yet plotted a continuous scale plot.

Any help would be much appreciated!