单击以下代码中的“向上”按钮会生成一系列图形,而不是更新现有图形。如何更新现有图形?
from IPython.html import widgets
import bokeh.plotting as bp
from IPython.display import display
from numpy.random import randn
bp.output_notebook()
m = 1000
n = 1000
df = pandas.DataFrame(randn(m, n)).cumsum()
bp.hold()
bp.figure(figsize=(4, 8))
def doplot(i):
bp.line(df.index, df.icol(i), color='red', legend='here')
bp.show()
class A:
def __init__(self):
self.i = 0
self.doplot()
def incr(self, something):
self.i += 1
print(self.i)
self.doplot()
def decr(self, something):
self.i -= 1
self.doplot()
def doplot(self):
doplot(self.i)
a = A()
button = widgets.ButtonWidget(description='up')
button.on_click(a.incr)
buttond = widgets.ButtonWidget(description='down')
buttond.on_click(a.decr)
display(button)
display(buttond)