jwass / mplleaflet

Easily convert matplotlib plots from Python into interactive Leaflet web maps.
BSD 3-Clause "New" or "Revised" License
521 stars 76 forks source link

Add the plot legend to the GeoJSON properties #35

Open ocefpaf opened 8 years ago

ocefpaf commented 8 years ago

I guess that mplleaflet follow the simplestyle-spec closely and what I propose here this is not in the simplestyle-spec, but it would be nice to use the legend information to create popups later on. (Or just to keep track of who-is-who in the JSON.)

@jwass is that something you would be OK to add? If so I can take try to implementing this.

jwass commented 8 years ago

@ocefpaf Can you provide an example? I've always wanted legends to show up on the final page.

One of the goals of mplleaflet is to allow plotting in matplotlib normally and it just "does the right thing" to generate the web page. Is there a way to create a legend using plt.legend and then just inspect that to create a legend on the resulting page?

ocefpaf commented 8 years ago

I've always wanted legends to show up on the final page.

Yeah, maybe that is better and more consistent with mplleaflet's goal. (But not exactly what I had in mind :wink:) l

Is there a way to create a legend using plt.legend and then just inspect that to create a legend on the resulting page?

Probably yes. Just not sure how to do it yet. What I was thinking was to just export GeoJSON with the label string information as a popup property for each geometry.

For example: in cell [5] of this notebook I add the drifter label to each line. The easiest way to propagate the drifter name to the map would be the save the label string in the "properties" field and then use it as a popup for each line.

BTW adding the actually legend in the final page could be done via two routes:

a) (the ugly hack) save the legend as a PNG images and add it using L.control

b) (the elegant solution) Create a custom legend control with the proper css, symbols, colors, and text. All exported from the original legend.

Right now I am selfishly thinking about just creating a mpl2geojson that has the functionality I need. As I learn more about leaflet I will try to get back to this issue and add export the legend.

jwass commented 8 years ago

Ah. I see. So use the matplotlib legend to set properties on the exported features? That would be really nice.