plotly / Kaleido

Fast static image export for web-based visualization libraries with zero dependencies
MIT License
380 stars 39 forks source link

write_image with large width does not save correcly #47

Open orena1 opened 4 years ago

orena1 commented 4 years ago

When saving a figure with a large width, the output of the figure just stops in the middle. When saving to HTML, it saved the full figure image

here is a simple example:

import plotly.express as px
import numpy as np
from plotly.subplots import make_subplots
import plotly.graph_objects as go

max_t = 62000
fig = make_subplots(rows=4, cols=1, start_cell="top-left",shared_xaxes=True ,
                   vertical_spacing=0.00004,row_heights=[3, 10    ,20,20], 
                   )

fig.add_trace(go.Scatter(x=list(range(max_t)), y=np.random.uniform(0,1,max_t)),
                       row=1, col=1)

fig.write_image(f"test_self.png",width=65400, height = 1500, engine='kaleido')
fig.update_layout(width=65400, height = 1500)
fig.write_html(f"test_self.html")

plotly.version: 4.10.0

Thanks

nicolaskruchten commented 4 years ago

Thanks for the bug report! Will transfer to the Kaleido repo :)

jonmmease commented 4 years ago

Thanks for the report @orena1.

Do you see the same behavior when you export the image by clicking on the camera icon in the toolbar of the HTML export? This will help us narrow down where the issue may be.

Also, it doesn't look like max_t is defined in your code example. Could you update that to make sure the code snippet can be copied and run directly? Thanks!

orena1 commented 4 years ago

Hi @jonmmease I've updated the code it is now self-contained.

Do you see the same behavior when you export the image by clicking on the camera icon in the toolbar of the HTML export? This will help us narrow down where the issue may be.

Very interesting, I've outputted the file to html (with the same dimensions) and when I try to save the html to png I get the same error.

I attached the files: drive-download-20200928T161933Z-001.zip

jonmmease commented 4 years ago

Thanks for checking @orena1. This actually does make sense because kaleido asks Plotly.js to export the figure to an image the same way the toolbar button does, so it will probably need to be fixed there. I'll try to reproduce in with Plotly.js directly and open an issue over there.

wcheek commented 2 years ago

I have been having this issue as well, but the behavior is different between an image saved from the html tool and one directly saved with fig.write_image(). With write_image(), if the layout width is small (2000) all traces get successfully saved to a .png: narrow from write_image. If the layout width is larger (6000), they fail to save: wide from write_image

I can write_html and save the wide format version just fine though: wide from write_html, which is slightly different than the issue described above.

plotly = "==5.4.0"