Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

Plot colorscale

Hi all,

I am using scatter with fill=“toself” to plot custom geographic polygons with colors. For the heat of the colors, I use a matplotlib coloscale. I know how to transfer the colorscale to the format plotly uses, but I am incapable of adding the colorbar to the scatter plot without adding markers. Is there some way to just plot the colorbar separate and add it? Or some other way?

My plotting is similar to: Create your own choropleth map with custom shapefiles


Hey @killver,
To add a colorbar to your plot you should define a dummy scatter plot, consisting in two points of small size and coordinates (a,b), (c,d), placed in your colored regions
Something like this one:

dummy_trace=(x=[a, c],
             y=[b, d],
             marker=dict(size=0.1, color=[min_val, max_val], 
             colorscale=your_colorscale, showscale=True),

min_val, respectively max_val are the values in your previous trace that are mapped to the color corresponding to 0, respectively 1.

Thanks @empet. That worked!