Jupyter中的mplseplayer在笔记本模式下避免空白?

2024-10-02 10:34:22 发布

您现在位置:Python中文网/ 问答频道 /正文

mplsaple在Jupyter笔记本中与“%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)

输出如下:

enter image description here


Tags: importmatplotlib模式figinline笔记本jupyterplt
1条回答
网友
1楼 · 发布于 2024-10-02 10:34:22

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

一种想法是不要使用%matplotlib notebook,这样放置图形mplseplayer图形的区域不会被未使用的图形填充。在

enter image description here

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

enter image description here

相关问题 更多 >

    热门问题