mplleaflet
mplleaflet copied to clipboard
popup window
It would be nice to have a popup window from the label property set from a mpl.scatter call ?
The bindPopup method from Leaflet is there to do so. Telling that, not sure to know how to do it.
Interesting request. It has been a while that I have been thinking about a package, derived from mpllleaflet
, to create a GeoJSON from a mpl figure (mpl2json
). The pieces are all there and I even have a working prototype.
The goal is to use that JSON
in any way you want. In my particular case I am interested in using folium to create plots similar to what you mentioned. But instead of a popup from the figure label it would be a HTML
table (but any thing is possible once you have the JSON
).
@jwass What do you think? Would you be OK with the imaginary mpl2json
package that both of us could use as a dependency to folium
and mplleaflet
?
Here is my test code to explore this missing feature so with the use of a mpld3 plugin as commented in https://github.com/jwass/mplleaflet/issues/5#issuecomment-42786751
%matplotlib inline
import pylab as plt
import mpld3, mplleaflet
fig = plt.figure()
ax = plt.gca()
x = np.random.randint(-10, high=20,size=10)
y = np.random.randint(40, high=50, size=10)
scatter = ax.scatter(x, y, s=150)
labels = []
for n,v in enumerate(x):
labels.append("%.2f, %.2f" %(x[n] , y[n]))
tooltip = mpld3.plugins.PointLabelTooltip(scatter, labels=labels)
mpld3.plugins.connect(fig, tooltip)
#mpld3.display()
mplleaflet.display()
It works nicely with use of mpl3.display() and would be very nice to have same plugin in mplleaflet.
Hi @PBrockmann @ocefpaf.
I'd love to consider a way popups could be included as part of the API here, though not sure if this would start to make it look like Folium.
Separately, mplleaflet already has a fig_to_geojson()
function, although it includes the styling information that gets used by the Javascript to create each layer on the map. We could make that more configurable to omit or insert more dynamic styling or feature properties
@PBrockmann I'll reopen for now :)
Yes, I have closed it by mystake.
I really appreciate the direct convertion from a matplotlib map to a slippy map, without dealing with many more ~~low level~~ definitions of circle_marker or polygon_marker as in folium.
Here is my current work on mapping paleoclimate data.
Just missing some tooltip or popup.
low level definitions of circle_marker or polygon_marker as in folium
Based on this comment I see that there is a reason to implement pop-ups directly in mplleaflet. Driving away @jwass fears of looking like folium. Even so, it is still nice to have some redundancies of thoughts and ideas out there, at lesat until libraries start to make sense.
(Although I strongly disagree that a folium's Python interface to Java's leaflet markers is low level :wink: )