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

How to customize download plot options? #326

Closed
ZenanH opened this issue May 15, 2020 · 6 comments
Closed

How to customize download plot options? #326

ZenanH opened this issue May 15, 2020 · 6 comments

Comments

@ZenanH
Copy link

ZenanH commented May 15, 2020

In the documentation for the Plotly Javascript, I noticed that the options for downloading plot can be changed. I would like to do a similar setup in PlotlyJS.jl to download plot directly in SVG format, what should I do? 😅
image

@disberd
Copy link
Member

disberd commented May 27, 2020

Hi @ZenanH,

You can use the options keyword argument to the PlotlyJS.plot function as explained at the bottom of this page of the documentation.

You can reproduce the linked example from the plotlyjs documentation by adapting to PlotlyJS.jl syntax with the following code:

using PlotlyJS

trace1 = scatter(
    x=[0, 1, 2, 3, 4, 5, 6],
    y= [1, 9, 4, 7, 5, 2, 4],
    mode= "markers",
    marker_size = [20, 40, 25, 10, 60, 90, 30]
)

layout = Layout(;
    title= "Download Chart as SVG instead of PNG",
    showlegend= false
);

config = Dict(
  :toImageButtonOptions => Dict(
    :format => "svg", # one of png, svg, jpeg, webp
    :filename => "custom_image",
    :height => 500,
    :width => 700,
    :scale => 1 # Multiply title/legend/axis/canvas sizes by this factor
  )
);
plot(trace1,layout;options=config)

@ZenanH
Copy link
Author

ZenanH commented May 27, 2020

Thanks, it worked! I hadn't noticed it in the documentation before.😅

@sglyon
Copy link
Member

sglyon commented May 27, 2020

thank you @disberd !!

Sorry for slow response @ZenanH

@sglyon sglyon closed this as completed May 27, 2020
@jwintersinger
Copy link

Hello! Unfortunately, the code above no longer works for me. If I call savefig(plot(trace1, layout, options=config), "out.html"), the image Plotly saves for me when I click the "download image" button is still a PNG at the default size. There's no record of any of the options I specified in plot_json within out.html. Is there perhaps an easy fix, given that PlotlyJS.jl doesn't seem to recognize options any longer?

Thanks!

@empet
Copy link

empet commented Feb 23, 2021

The following lines of code do save a html version of the plot:

pl = plot(trace, layout, style=plotlyju) #plotlyju.jl is my style file  #https://gist.github.com/empet/6b4f441ed96d724d67ff77f1fb8b0a79
savefig(pl, "surf.html")

If you are working with the default style, then remove the style setting from the plot definition.

@jwintersinger
Copy link

Thanks, @empet! Unfortunately, that part was already working for me -- I have no problem writing the HTML file and having the plot render in my browser. My issue is specifically with being able to specify the format and dimensions of the image that the browser will save when I click Plotly's "download image" button.

In fact, in the PlotlyJS.jl source tree, the minimal example given in PlotlyJS.jl/docs/src/syncplots.md doesn't work for me, so I'll open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants