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)
基础教程推荐
猜你喜欢
- 如何在 Python 中检测文件是否为二进制(非文本)文 2022-01-01
- 使用Python匹配Stata加权xtil命令的确定方法? 2022-01-01
- Python 的 List 是如何实现的? 2022-01-01
- 哪些 Python 包提供独立的事件系统? 2022-01-01
- 症状类型错误:无法确定关系的真值 2022-01-01
- 合并具有多索引的两个数据帧 2022-01-01
- 使 Python 脚本在 Windows 上运行而不指定“.py";延期 2022-01-01
- 使用 Google App Engine (Python) 将文件上传到 Google Cloud Storage 2022-01-01
- 如何在Python中绘制多元函数? 2022-01-01
- 将 YAML 文件转换为 python dict 2022-01-01