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
- Kivy 使用 opencv.调整图像大小 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
