question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Plotly.downloadImage seems to not always respect layout setting

See original GitHub issue

As mentioned here https://github.com/plotly/plotly.js/issues/2098#issuecomment-337622647 Plotly.downloadImage should accept a layout object and it does normally. When you define your layouts like I did in the following fiddle, it never respects a given layout object but rather chooses the layout object used for drawing the plot. (You can switch plotLayout and downLayout in the given fiddle around to test this.)

https://jsfiddle.net/7co1nf0v/

So how can I achieve keeping this namespace but also being able to pass a different layout for the downloadImage than for the plot drawing? Please point me towards any mistakes I may have made, I’m not totally firm with JavaScript yet. 😹

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
alexcjohnsoncommented, Sep 17, 2018

(BTW, this kind of question is a better fit for community.plot.ly - github issues should be for bug reports or feature requests)

That’s the intended behavior. We could certainly do a better job of describing this in the docs… but you can’t put data or layout into the second argument, they need to be in the first argument (either directly, as you have it in your second fiddle, or already attached to a div).

Plotly.downloadImage is a wrapper around Plotly.toImage, which is described more in the source

If anyone can point me towards how I could reuse the given graph and just “overload” it with another layout, so I don’t need to redraw everything in the background

No matter what you do, we’re going to redraw the plot in the background when you ask for an image of it, since the image options can change how it is drawn. But the way you do it in your second fiddle is the correct way to do it, there are no unnecessary redraws there.

1reaction
antoinergcommented, Sep 17, 2018

Hello @Braintelligence and thank you for reporting this!

From my understanding, Plotly.downloadImage will only honor a layout object if it is provided in the first argument. In your first fiddle, the layout object is provided in the second argument which is why it doesn’t work. Your second fiddle does work because the layout is provided in the first argument!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use plotly offline to save chart as image file
I made a script using selenium. It seems to work for webgl plots. import time from selenium import webdriver profile = webdriver.FirefoxProfile() profile....
Read more >
Function reference in JavaScript - Plotly
The layout of the plot – non-data-related visual attributes such as the title, annotations etc – is described in an object usually called...
Read more >
Plot sizing problems - plotly.js - Plotly Community Forum
When autosize comes into play, it seems to always pick a height of 450px ... With autosize not set, the width of the...
Read more >
Python Figure Reference: layout - Plotly
Sets the title's horizontal alignment with respect to its x position. "left" means that the title starts at x, "right" means that the...
Read more >
Static image export in Python - Plotly
Detailed examples of Static Image Export including changing color, size, log axes, and more in ... Plotly allows you to save static images...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found