When enabling editable, drawline etc. and eraseshape for the Graph object, the eraseshape functionality does not work since the shapes can not be selected and only moved.
Is there a way to select these shapes when editable = True?
Hi @DolanDuk welcome to the forums.
Just click on the concerning shape- it should change itβs color. Then click eraseshape
.
This only seems to work if editable is set to False, in the case where it is set to true, selection seems to default to changing the position of the shape or resizing it. Selecting it does not seem to work.
Minimal example where it doesnt work:
plotly version 5.13.1
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Scatter(x=[1, 2, 3, 4, 5], y=[1, 3, 2, 4, 5], mode='markers'))
config = {'modeBarButtonsToAdd': ['drawline', 'eraseshape'], 'editable': True}
fig.show(config=config)
example where it works
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Scatter(x=[1, 2, 3, 4, 5], y=[1, 3, 2, 4, 5], mode='markers'))
config = {'modeBarButtonsToAdd': ['drawline', 'eraseshape'], 'editable': False}
fig.show(config=config)
This is strange. Even if you set editable=False, the created shape is editable.
import plotly.graph_objects as go
# prepare data
data = go.Scatter(
x=[1, 10],
y=[1, 10],
mode='markers',
marker={
'size': 8,
'symbol': 'circle-open',
},
)
# create figure
fig = go.Figure(data=data)
# add shape
fig.add_shape(
{
'type':'rect',
'x0': 3, 'x1': 5,
'y0': 3, 'y1': 5,
},
editable=True,
name='shape_1',
)
fig.add_shape(
{
'type':'rect',
'x0': 8, 'x1': 9,
'y0': 8, 'y1': 9,
},
editable=True,
name='shape_2',
)
# show figure
config = {'modeBarButtonsToAdd': ['drawline', 'eraseshape'], 'editable': False}
fig.show(config=config)
Do you need the created shapes to be non- editable?
I need the Users to be able to change the title etc. and add shapes to the Plot, therefore i used the drawline and other shapes aswell as the editable feature which enables changing the title etc. The problem is, that users would now need to reload the plot to remove added shapes.
It doesnβt matter that much, whether the users can change shapes after inserting them. I need the editable feature mainly to change the title and axis labels in the plot.
The only solution i can think of is adding a Button which removes these shapes from the plot (The figure is inside a dash app), but this would make the UI less appealing