artursp.
artursp.
SSolara
Created by artursp. on 3/26/2024 in #questions-issues
Using existing plotly widget to update figures
With go.FigureWidget it is possible to update the data/properties of a figure without redrawing it. E.g. I can create a scatter plot with a lot of points:
N = 1000000
fig = go.FigureWidget(
data=go.Scattergl(
x = np.random.randn(N),
y = np.random.randn(N),
mode='markers',
selected=go.scattergl.Selected(marker = {"color":"red", "size":25}),
selectedpoints=[5,10,25]
)
)
N = 1000000
fig = go.FigureWidget(
data=go.Scattergl(
x = np.random.randn(N),
y = np.random.randn(N),
mode='markers',
selected=go.scattergl.Selected(marker = {"color":"red", "size":25}),
selectedpoints=[5,10,25]
)
)
and then update the highlighted points without redrawing it the whole thing:
scatter = fig.data[0]
scatter.selectedpoints = np.random.randint(0,N,size=50)
scatter = fig.data[0]
scatter.selectedpoints = np.random.randint(0,N,size=50)
The straight forward solara equivalent could look like this:
N = 1000000
selected = solara.reactive([5,10,25])

x = np.random.randn(N)
y = np.random.randn(N)

def rand_sel():
selected.set(np.random.randint(0,N,size=50))

@solara.component
def Page():
fig = go.FigureWidget(
data=go.Scattergl(
x = x,
y = y,
mode='markers',
selected=go.scattergl.Selected(marker = {"color":"red", "size":25}),
selectedpoints=selected.value
)
)

solara.FigurePlotly(fig)
solara.Button('Random select', on_click=rand_sel)

Page()
N = 1000000
selected = solara.reactive([5,10,25])

x = np.random.randn(N)
y = np.random.randn(N)

def rand_sel():
selected.set(np.random.randint(0,N,size=50))

@solara.component
def Page():
fig = go.FigureWidget(
data=go.Scattergl(
x = x,
y = y,
mode='markers',
selected=go.scattergl.Selected(marker = {"color":"red", "size":25}),
selectedpoints=selected.value
)
)

solara.FigurePlotly(fig)
solara.Button('Random select', on_click=rand_sel)

Page()
but this will generally run slower as the figure is redrawn IIUC. Is there a way to update the figure using the plotly widget within solara?
3 replies
SSolara
Created by artursp. on 1/3/2024 in #questions-issues
Keep zoom state of plotly figure when re-render is triggered.
I built an app where I have a coloured scatter plot with many thousand points each associated with an image from a set of classes. I can select points, look at the image and reclassify. When I want to re render my scatter plot so that it has the updated classes I change a reactive dataframe. This all works fine, the only issue is that I have to zoom into a region of the scatter plot to resolve the points. Re-rendering resets the axes so I have to find that region again (but I have to re-render regularly to keep track of which points I processed). So the question is if there is a way to update the scatter plot (i.e. the point colors) without resetting the axes.
4 replies
SSolara
Created by artursp. on 12/21/2023 in #questions-issues
Remove controls from plotly figure
I'm using plotly to create clickable images that are tightly arranged. For this I need to remove the plotly controls. This can be done by passing config={'displayModeBar': False} to plotly.show, but as this is not a figure property I'm not sure how to accomplish this when doing solara.FigurePlotly(fig).
9 replies