I have a Jupyter lab notebook that loads an image dataset and then I use Plotly graph_objs to display the image.
What I would like to be able to do is draw a polygon (or circle) region on the image using the mouse and get the region information back in Python. But, I don’t see any simple way to do it (well, or complex, either). In the menu in the top right at one point I did see a way to draw a box, but it was not persistent and I didn’t see a way to get the corner information back in Python.
So, is there a way to draw polygons or circles, using the mouse, on a heatmap and get the region information back into Python. It would also be important to be able to move and delete the regions.
from ipywidgets import IntSlider
import ipywidgets
import numpy as np
import plotly.graph_objs as go
class Viewer:
def __init__(self):
# Load the data
self._image_data = np.random.random((256, 256))
self.create_image()
# Create the float view
self._sl = IntSlider(description='Slice #:', max=20)
self._fig = go.FigureWidget(self._gofig)
# Display the float view
display(ipywidgets.widgets.VBox([self._fig, self._sl]))
def create_image(self):
self._current_slice = 0
self._trace1 = {
"x": np.arange(74),
"y": np.arange(74),
"z": self._image_data,
"type": "heatmap"
}
self._data = go.Data([self._trace1])
layout = {
"xaxis": {
"gridcolor": "rgb(255,255,255)",
"showgrid": True,
"showline": False,
"showticklabels": True,
"tickcolor": "rgb(127,127,127)",
"ticks": "outside",
"title": "x",
"type": "linear",
"zeroline": False
},
"yaxis": {
"gridcolor": "rgb(255,255,255)",
"showgrid": True,
"showline": False,
"showticklabels": True,
"tickcolor": "rgb(127,127,127)",
"ticks": "outside",
"title": "y",
"type": "linear",
"zeroline": False,
"scaleanchor": "x"
}
}
self._gofig = go.Figure(data=self._data, layout=layout)
v = Viewer()