pbugnion / gmaps

Google maps for Jupyter notebooks
https://jupyter-gmaps.readthedocs.io/en/stable/
Other
760 stars 147 forks source link

Add a legend to a heatmap #278

Open labeeba opened 5 years ago

labeeba commented 5 years ago

Hi, I am using your gmaps library for a research project. I am using latitude and longitude values to generate a heatmap using the following code:

locations= list(zip(lat,lon))
fig.add_layer(gmaps.heatmap_layer(locations))
embed_minimal_html('heatmap.html', views=[fig])

I could not find a way to add a legend to the heat map to indicate how the colors (red, yellow, green) correspond to the density. In other words, how can I get the values/weight for these colors to better understand the heatmap? How do I create such a legend? Thanks

pbugnion commented 5 years ago

Thanks for raising this.

There is no way to do this directly through this (because, afaik, Google maps itself doesn't support it). However, you should be able to integrate with Jupyter widgets. For sample code, see issue #210, for instance.

labeeba commented 5 years ago

Thanks for your reply.

I found the default gradient used for the heatmap colors. ["rgba(102, 255, 0, 0)", "rgba(102, 255, 0, 1)", "rgba(147, 255, 0, 1)", "rgba(193, 255, 0, 1)", "rgba(238, 255, 0, 1)", "rgba(244, 227, 0, 1)", "rgba(249, 198, 0, 1)", "rgba(255, 170, 0, 1)", "rgba(255, 113, 0, 1)", "rgba(255, 57, 0, 1)", "rgba(255, 0, 0, 1)"]

  1. How could I use Jupyter widgets to visualize the above gradient?
  2. If I start my legend at 0 having least density, how do I find the value for the maximum density i.e bright red - rgba(255, 0, 0, 1)?