-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ENH] generate Plotly choropleth map of US states & clusters #16
Conversation
…nce/us_climate_emotions_map into adai/setup-app-nav
I have made some changes to @koudyk's code, in the new (and badly named) The figure has a few traces/layers:
Haven't implemented the impact things yet, but I see in the meeting minutes that we said to test these two approaches:
I can try both and show screenshots of what that looks like sometime next week, but if someone else would like to try, then please go for it! I need to work on #5 now 😅 |
For this one I think |
@alyssadai added visualization of impact data. Now there are three possible views. Opinion data only: fig = make_map(
question="q2",
sub_question=1,
outcome="3+",
clicked_state="Colorado, New Mexico (Cluster E)",
) Impact data only: fig = make_map(
question="q2",
sub_question=1,
outcome="3+",
clicked_state="Colorado, New Mexico (Cluster E)",
impact="wildfire",
show_impact_as_gradient=True,
) Opinion + impact data: fig = make_map(
question="q2",
sub_question=1,
outcome="3+",
clicked_state="Colorado, New Mexico (Cluster E)",
impact="wildfire",
show_impact_as_gradient=False,
) More notes:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @michellewang, very cool PR. I left a couple of comments - mainly for my own understanding. Take a look and see where you agree.
One change I would suggest is to not have a separate colormap for the impact markers (only when impact + opinions are shown at the same time). We already encode impact by the size of the markers - and the impact + opinion color maps clash a bit as well.
return json.loads( | ||
(Path(__file__).parents[1] / "code" / "assets" / file).read_text(), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍒 do you need the read_text
if you would use json.load
instead of json.loads
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, but you would have to explicitly open the file first and I thought that was a little simpler since we had pathlib.Path
s anyway
climate_emotions_map/make_map.py
Outdated
if __name__ == "__main__": | ||
|
||
# pick a random state/cluster to highlight | ||
states = state_abbreviations["state"].tolist() | ||
clicked_state = np.random.choice(states) | ||
# clicked_state = "Colorado, New Mexico (Cluster E)" # example cluster | ||
print(f"clicked_state: {clicked_state}") | ||
|
||
fig = make_map( | ||
question="q2", | ||
sub_question=1, | ||
outcome="3+", | ||
clicked_state=clicked_state, | ||
impact="wildfire", | ||
show_impact_as_gradient=False, | ||
) | ||
|
||
fig.show() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is here mainly for testing, yes?
hovertemplate=( | ||
"<b>%{customdata[0]}</b>" | ||
"<br>Sample size: %{customdata[1]}" | ||
f"<br>{col_gradient.capitalize()}: %{{z:.2f}}" | ||
f"{hovertemplate_extra}" | ||
"<extra></extra>" | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
neato
climate_emotions_map/make_map.py
Outdated
"color": px.colors.sample_colorscale( | ||
impact_colormap, | ||
(row[col_color_impact] - vmin_impact) | ||
/ (vmax_impact - vmin_impact), | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is very cool, but I feel like just relying on the size of the marker to encode the (relative) impact response is clearer to see. The colormap for impact is pretty close to the one for opinions (and we may not be able to find two maps that are completely orthogonal) - so they clash a little. And I don't think we (want to) have two separate color maps for opinion and impact either.
So maybe just size? For extra happiness, you could consider using emojis instead of circles: https://community.plotly.com/t/i-want-to-use-custom-icon-for-the-scatter-markers-how-to-do-it/6644/6 (not sure if that would still be able to scale though, so maybe not)
Warning
rebase on main after #9 is merged for a cleaner diff and easier review
takes @koudyk PR from previous repo and implements it here on top @alyssadai PR to use data loaders