def show_training(self, div_id, div_costs_curve, cost_values) :
#div_id = self.show(*args, **kwargs)
def change_frame(w) :
#print(w)
updates = self.get_frame(w-1)
script = ''
for i in range(len(updates[0])) :
jupdate = json.dumps(updates[0][i], cls=utils.PlotlyJSONEncoder)
jupdate_cost = json.dumps(dict(x = [[w]], y = [[cost_values[w-1]]]), cls=utils.PlotlyJSONEncoder)
script = script \
+ 'Plotly.restyle("{id}", {update}, [{index}]);'.format(
id=div_id,
update=jupdate, index = updates[1][i]) \
+ 'Plotly.restyle("{id}", {update}, [{index}]);'.format(
id=div_costs_curve,
update=jupdate_cost, index = 1)
update_str = (
'<script type="text/javascript">' +
'window.PLOTLYENV=window.PLOTLYENV || {{}};' +
'window.PLOTLYENV.BASE_URL="' + 'https://plot.ly' + '";' +
'{script}' +
'</script>').format(script=script)
#print(script)
display(HTML(update_str))
#print(self.frames)
maxframe = len(self.frames) - 1
play = Play(value=maxframe)
slider = IntSlider(min=1, max=maxframe, step=1, value=maxframe,continuous_update=False)
slider.layout.width = '100%'
#jslink((play, 'value'), (slider, 'value'))
traitlets.link((play, 'value'), (slider, 'value'))
hb = HBox([play, slider])
slider.observe((lambda iteration : change_frame(iteration['new'])), names='value')
change_frame(maxframe)
#play.observe((lambda iteration : print(iteration['new'])), names='value')
#display(hb)
return hb
评论列表
文章目录