-
Notifications
You must be signed in to change notification settings - Fork 1
Disable autosize on double click #149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disable autosize on double click #149
Conversation
Thanks for your pull request! Could you please add a comment (in the same code cell) explaining that this is for disabling autosize because of unwanted margins, and on another comment line link to https://plot.ly/python/configuration-options/? Then I'll merge :-) |
@emmanuelle Thanks for the comment! I updated the code. |
If we don't use the autosize, the dummy scatter trace can be omitted. |
Thank you very much! Merging 💃 :-) |
@emmanuelle Thanks for merging! What do you think about this?
I think it should be removed because it's no longer necessary. |
It seems like this example will be much nicer/easier when the image trace type comes out :) no more “dummy” traces |
@nicolaskruchten That'd be great! When will it come out? I actually used this feature on this PR (mlflow/mlflow#1934) but it was a bit of pain to fill out all the layout options. |
btw the dummy trace can be removed. I tested the following code on Binder and it worked. import plotly.graph_objects as go
# Create figure
fig = go.Figure()
# Constants
img_width = 1600
img_height = 900
scale_factor = 0.5
- Add invisible scatter trace.
- This trace is added to help the autoresize logic work.
- fig.add_trace(
- go.Scatter(
- x=[0, img_width * scale_factor],
- y=[0, img_height * scale_factor],
- mode="markers",
- marker_opacity=0
- )
- )
# Configure axes
fig.update_xaxes(
visible=False,
range=[0, img_width * scale_factor]
)
fig.update_yaxes(
visible=False,
range=[0, img_height * scale_factor],
# the scaleanchor attribute ensures that the aspect ratio stays constant
scaleanchor="x"
)
# Add image
fig.update_layout(
images=[go.layout.Image(
x=0,
sizex=img_width * scale_factor,
y=img_height * scale_factor,
sizey=img_height * scale_factor,
xref="x",
yref="y",
opacity=1.0,
layer="below",
sizing="stretch",
source="https://raw.githubusercontent.com/michaelbabyn/plot_data/master/bridge.jpg")]
)
# Configure other layout
fig.update_layout(
width=img_width * scale_factor,
height=img_height * scale_factor,
margin={"l": 0, "r": 0, "t": 0, "b": 0},
)
# Disable the autosize on double click because it adds unwanted margins around the image
# More detail: https://plot.ly/python/configuration-options/
fig.show(config={'doubleClick': 'reset'}) |
Doc upgrade checklist:
unconverted/x/y.md
tox/y.md
plot()
oriplot()
graph_objs
has been renamed tograph_objects
fig = <something>
call is high up in each exampletrace
objectsadd_trace
andupdate_layout
fig.show()
at the end of each examplepx
example at the top if appropriatehttps://plot.ly/python/images/#zoom-on-static-images
This PR proposes to disable
autosize
on double click and use onlyreset
becauseautosize
adds margins around the image.Current (example on the doc)
Proposed (tested on Jupyter)