Only one line of code is needed to convert a plot into a web map.
The simplest use is to just create your plot using matplotlib commands and call
>>> import matplotlib.pyplot as plt ... # Load longitude, latitude data >>> plt.hold(True) # Plot the data as a blue line with red squares on top # Just plot longitude vs. latitude >>> plt.plot(longitude, latitude, 'b') # Draw blue line >>> plt.plot(longitude, latitude, 'rs') # Draw red squares
Normally, displaying data as longitude, latitude will cause a cartographer to cry. That's totally fine with mplleaflet, Leaflet will project your data properly.
# Convert to interactive Leaflet map >>> import mplleaflet >>> mplleaflet.show()
Disclaimer: Displaying data in spherical mercator might also cause a cartographer to cry.
show() allows you to specify different tile layer URLs, CRS/EPSG codes, output files, etc.
IPython Notebook embedding
mplleaflet.display() to embed the interactive Leaflet map in an IPython notebook.
Click here to see a live example.
- basic_plot.py: Simple line/point plotting. View the map.
- quiver.py: Demonstrates use of quiver() to plot 2-D arrows. View the map.
- contour.py: Compute contour curves. This example demonstrates plotting in a different CRS and letting mplleaflet convert the output. View the map.
- Embedded IPython notebook example
Other Python libraries, basemap and
folium, exist to create maps in Python. However mplleaflet allows you to leverage all matplotlib capability without having to set up the background basemap. You can use
plot() to style points and lines, and you can also use more complex functions like
quiver(), etc. Furthermore, with mplleaflet you no longer have to worry about setting up the basemap. Displaying continents or roads is determined automatically by the zoom level required to view the physical size of the data. You should use a different library if you need fine control over the basemap, or need a geographic projection other than spherical mercator.
mplleaflet from PyPI using
$ pip install mplleaflet.
If developing for
mplexporter is a git submodule with its
Python package files placed under the
mplleaflet package. The Makefile
copies the files into the appropriate location.
$ git submodule init $ git submodule update $ make $ pip install -e .