Hi, thanks for this wonderful tool. I was doing some experiments using plotly instead of matplotlib in jupyter notebook for image analysis. I usually iterate on image dataset using ipython widgets. Using %matplotlib notebook I am able to update the current image while with plotly it seems I canβt. Each time I change the image a new image is displayed under the previous one on the cell output. I have read the related answers here but they did not work. This is the code I am using I was wondering if you could give me some hints. Thanks!
from IPython.display import display
import ipywidgets as widgets
import plotly.graph_objects as go
class ImageViewer():
def __init__(self):
self.fig = None
self.opendata()
def opendata(self):
self.W_canvasID = widgets.IntText(
description="IMAGE ID:")
print("CREATING IMAGE")
self.fig = go.FigureWidget([]);
def update_image(canvasindex):
# Add image
img_width = 1600
img_height = 900
scale_factor = 0.5
self.fig.add_layout_image(
x=0,
sizex=img_width,
y=0,
sizey=img_height,
xref="x",
yref="y",
opacity=1.0,
layer="below",
source="https://picsum.photos/%s00" %str(int(self.W_canvasID.value)+1)
);
print('ADDING')
self.fig.update_xaxes(showgrid=False, range=(0, img_width));
self.fig.update_yaxes(showgrid=False, scaleanchor='x', range=(img_height, 0));
self.fig.show(config={'modeBarButtonsToAdd':['drawline',
'drawopenpath',
'drawclosedpath',
'drawcircle',
'drawrect',
'eraseshape'
]});
self.fig.update_layout_images()
# used by the selector
self.W_canvasID.observe(update_image,names='value')
display(self.W_canvasID)
update_image(0)
return True
v = ImageViewer()