Black Lives Matter. Please consider donating to Black Girls Code today.

Overlaying Trace(s) over USA Choropleth

Hi there, I’m looking to overlay the Nielson Designated Market Area over the Full County Choropleth in Plotly.

Thus far, I have generated a choropleth with respect to my feature variable and plotted at the FIPS level. Now, I would like to draw polygons around fips that are in the same Designated Market Area (perhaps alternate the color across the polygon borders, or just make them thicker lines-In the end I just want to know how the fips level data lines up along dma).

I have written a dictionary that maps FIPS to DMA-however, I am unsure how to add another “trace” over my choropleth object.

Thanks for the help!

Hi @brawthy,

This is a neat idea. The county outlines are standard scatter traces, so it if you can figure out the coordinates for what you want, it would be possible to add additional traces to the figure returned by create_choropleth.

Something like:

fig = ff.create_choropleth(...)
fig.add_traces(new_traces_list)
iplot(fig)

To actually understand how the current county outlines are calculated, I’d recommend reading through and working to understand the create_choropleth code itself (https://github.com/plotly/plotly.py/blob/master/plotly/figure_factory/_county_choropleth.py).

Good luck!
-Jon

Hi Jon, thanks for the reply!

I’m looking under the definition of create_choropleth, and I don’t see the data parameter. Are you implying that i should write a dictionary for the trace in the form (fips,value,outline), and append those piecemal to their related parameters?

Ideally I’m looking to join fips locations with a polygon that surrounds them-in this case I would like to map fips data to nielson designated market zones (dmas) and visually denote these unique dmas with a bold line (for all dmas)

Hi @brawthy,

I didn’t really have a particular approach in mind, and I expect it would take a fair bit of work no matter how you were to go about it. I was only trying to point out that it’s possible to add traces to a figure produced by a figure factory, and that it might be helpful for you to understand what the current figure factory does.

-Jon

Did anyone figure out?
I created county choropleth and would like to add some points to the choropleth map. Do you know how to add the points with coordinates to the map? Thank you!