【发布时间】:2022-11-24 02:05:05
【问题描述】:
我有一个场景,我想在运行小部件之前初始化绘图并在其上绘制一堆东西。但是,jupyter 小部件拒绝在我已经绘制的图上绘制。相反,什么也没有出现。下面是一个简化的例子。
import matplotlib.pyplot as plt
import ipywidgets as widgets
from IPython import display
fig=plt.figure(1,(2,2))
axs=fig.gca()
def testAnimate(x):
axs.text(0.5,0.5,x)
xs=widgets.IntSlider(min=0,max=3,value=1) #Create our intslider such that the range is [1,50] and default is 10
gui = widgets.interactive(testAnimate, x=xs) #Create our interactive graphic with the slider as the argument
display.display(gui) #display it
我希望 x 的值显示在 axs 上,但它没有。我意识到在这种情况下我可以只做 plt.text,但是在我的实际项目中这是不可行的。那么,如何让 x 的值显示在我的绘图中?
谢谢!
【问题讨论】:
标签: python matplotlib jupyter-lab ipywidgets