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)
基础教程推荐
猜你喜欢
- 修改列表中的数据帧不起作用 2022-01-01
- 包装空间模型 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 求两个直方图的卷积 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
