Jupyter: How to update plot on button click (ipywidgets)(Jupyter:如何在单击按钮时更新绘图(Ipywidgets))
本文介绍了Jupyter:如何在单击按钮时更新绘图(Ipywidgets)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Jupyter,并尝试使我的绘图具有交互性。
所以我有一个图。我有一个ipywidgets按钮。
单击按钮时,我需要更新绘图,就像使用滑块进行交互一样。
但我不能。
只有当matplotlib使用‘Notebook’后端时,它才能工作,但它看起来很糟糕。同时,Interactive可以处理任何类型的情节。是否有方法可以不使用InterAct重现此内容?
#this works fine! But toolbar near the graph is terible
#%matplotlib notebook
#this does not work
%matplotlib inline
from matplotlib.pyplot import *
button = ipywidgets.Button(description="Button")
def on_button_clicked(b):
ax.plot([1,2],[2,1])
button.on_click(on_button_clicked)
display(button)
ax = gca()
ax.plot([1,2],[1,2])
show()
推荐答案
作为解决办法,我们可以将整个绘图重新绘制到输出小工具,然后不闪烁地显示它。
%matplotlib inline
from matplotlib.pyplot import *
button = ipywidgets.Button(description="Button")
out = ipywidgets.Output()
def on_button_clicked(b):
with out:
clear_output(True)
plot([1,2],[2,1])
show()
button.on_click(on_button_clicked)
display(button)
with out:
plot([1,2],[1,2])
show()
out
这篇关于Jupyter:如何在单击按钮时更新绘图(Ipywidgets)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:Jupyter:如何在单击按钮时更新绘图(Ipywidgets)


猜你喜欢
- 使用Heroku上托管的Selenium登录Instagram时,找不到元素';用户名'; 2022-01-01
- pytorch 中的自适应池是如何工作的? 2022-07-12
- 分析异常:路径不存在:dbfs:/databricks/python/lib/python3.7/site-packages/sampleFolder/data; 2022-01-01
- 如何在 python3 中将 OrderedDict 转换为常规字典 2022-01-01
- python-m http.server 443--使用SSL? 2022-01-01
- 如何将一个类的函数分成多个文件? 2022-01-01
- 如何在 Python 的元组列表中对每个元组中的第一个值求和? 2022-01-01
- 沿轴计算直方图 2022-01-01
- padding='same' 转换为 PyTorch padding=# 2022-01-01
- python check_output 失败,退出状态为 1,但 Popen 适用于相同的命令 2022-01-01