jwass / mplleaflet

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

Add figsize option in _repr_html_ #22

Open BibMartin opened 9 years ago

BibMartin commented 9 years ago

My idea when computing https://github.com/jwass/mplleaflet/commit/3f4fc1b2728ca8de075102deaf2d4223c2ac81e8 was to display in the notebook a figure with the same size as matplotlib figures. If you tune your figsize, it will keep the same shape :

fig = plt.figure(figsize=(17,10))
plt.plot(...)
mplleaflet.display(fig)

But as @jwass notice in https://github.com/jwass/mplleaflet/commit/1c1ce59802fded851edb6c8b62f006abcb6c798a, the defaut matplotlib figure is tiny (and ugly for a map).

This PR adds a figsize option in the display, so that mplleaflet.display(fig) will keep the figure size, and mplleaflet.display(fig,figsie="100%") will enalble to use the full width of the output cell. By the way, this latter example will keep the figure's aspect ratio.

You can also force the output size like:

mplleaflet.display(fig, figsize=("60%","150px"))
mplleaflet.display(fig, figsize=(17,5))
mplleaflet.display(fig, figsize="60%")