Skip to content
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

Orientation & marker size changes on static export of vector graphics. #187

Open
drscotthawley opened this issue Apr 2, 2023 · 2 comments
Labels
bug something broken P3 not needed for current cycle

Comments

@drscotthawley
Copy link

drscotthawley commented Apr 2, 2023

Following the Plotly documentation for static image export:
https://plotly.com/python/static-image-export/

When I try to save the figure using the suggested call to fig.write_image, it ignores my rotation and zoom adjustments and saves with some default orientation and a much larger marker size. The documentation says nothing about this, or how to fix it.

As an example to reproduce this problem, let's take the 3D Scatter plots documentation example (I'll add a light height to it too):

import plotly.express as px
df = px.data.iris()
fig = px.scatter_3d(df, x='sepal_length', y='sepal_width', z='petal_width',
              color='species', height=500)
fig.show()

If i execute this in a Jupyter cell, I can rotate the graph, press the "Download as PNG" button, and get exactly what I see. For example, this image:
fig1

But if I then run the recommended export code to save a PDF,

fig.write_image("fig1.pdf")

and then view the PDF file, I see something different: the orientation resets and the marker size is huge (screenshot):
Screen Shot 2023-04-02 at 5 41 51 PM

Given that the docs don't address this, I'm wondering if it's a bug. Otherwise, there's quite an omission in the documentation.

Either way, my question is how can we export vector images that preserve orientation & marker size? Thanks.

(Workaround: Currently I'm trying to "guess" my camera controls to set them programmatically before the save, but it's a slow iterative process. If there's a way to query fig.layout.scene.camera.whatever to then go back to fix the camera for save, please let me know. And add it to the docs! Marker size is the same thing -- I know what markers I see, but have to keep re-saving and checking the size because it's a different size in the PDF. :-( )

Version info:

$ pip list | grep 'plotly\|kaleido'
kaleido                   0.2.1
plotly                    5.14.0
$ python --version
Python 3.10.6
@drscotthawley
Copy link
Author

Update: I do have Kaleido installed but hadn't invoked the export settings. If I add the code

import plotly.io as pio
pio.kaleido.scope.default_format = "pdf"

and run it before the fig.write_image call....nothing different happens. :-( The PDF is still "wrong".

@gvwilson gvwilson transferred this issue from plotly/plotly.py Jul 11, 2024
@gvwilson gvwilson self-assigned this Jul 26, 2024
@gvwilson
Copy link
Collaborator

Thanks for your interest in Kaleido. We are currently working on an overhaul that might address your issue - we hope to have news in a few weeks and will post an update then. Thanks - @gvwilson

@gvwilson gvwilson removed their assignment Aug 3, 2024
@gvwilson gvwilson added bug something broken P3 not needed for current cycle labels Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken P3 not needed for current cycle
Projects
None yet
Development

No branches or pull requests

2 participants