【问题标题】:mplleaflet in Jupyter - avoid whitespace with notebook mode?Jupyter 中的 mplleaflet - 使用笔记本模式避免空格?
【发布时间】:2018-07-29 00:58:38
【问题描述】:

mplleaflet 与 Jupyter Notebook 中的“%matplotlib inline”模式配合得很好,但是当启用“%matplotilib notebook”模式时,单元格和地图之间有一大块空白。这可以避免吗?

代码:

import matplotlib.pyplot as plt
import mplleaflet

%matplotlib notebook

#some latitudes bracketing seattle
lats = [47.5062,47.7062]
#longitude
lons = [-122.3321]*len(lats)

fig,ax=plt.subplots(figsize=(8,8))
ax.scatter(lons, lats, alpha=0) #invisible data points, just to scale the map

mplleaflet.display(fig=fig)

输出如下:

【问题讨论】:

    标签: python matplotlib leaflet jupyter-notebook jupyter


    【解决方案1】:

    问题是创建了一个应该在笔记本中显示的图形。但是,您不希望将 mplleaflet 图显示为具有 %matplotlib notebook 后端的交互式图。

    一个想法是不使用%matplotlib notebook,这样放置图mplleaflet图的区域就不会被未使用的图填充。

    在使用%matplotlib notebook 时,也可以使用%%capture 来抑制输出。然后在新的未捕获单元格中调用mplleaflet.display

    【讨论】:

    • 谢谢。捕获建议是一个不错的解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-13
    • 1970-01-01
    • 2016-03-04
    • 2022-08-04
    相关资源
    最近更新 更多