我对Python、Matplotlib和ipywidget没有太多的经验。我正在尝试建立一个jupyter交互式笔记本,显示一张地图,然后叠加不同的海洋等深线(等深线)。我想在一系列复选框的帮助下显示/隐藏一些行。问题是一旦选择了一些线,就要重新绘制地图。所以策略是 示意图:
%matplotlib inline
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
from ipywidgets import *
from IPython.display import display
load_map() # loads isobaths from files (arrays of lat,lon pairs)
def draw_mapa(): #draw the map
mapa = Basemap()
mapa.drawcoastlines()
def draw_level(level): #draw a specific line (z=level)
mapa.plot(x,y)
def on_level_change(change): #handler of checkboxes
draw_mapa()
if button is True:
draw_level(level)
display(container) #container with all the checkboxes
#attaching handler to checkbox through .observe() method
for ilevel in checkboxes:
ilevel.observe(on_level_change,names='value')
除了我开始与复选框交互时,一切正常。每次我选择/取消选择一个框时,都会出现一个带有修正等深线的新附加地图。在
所以问题是如何在一个图形中正确地“过批”避免每次选中一个框时都创建新实例。在
谢谢
目前没有回答
相关问题 更多 >
编程相关推荐