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 savefig with dpi=300 #361

Open
biona001 opened this issue Jan 7, 2021 · 7 comments
Open

how to savefig with dpi=300 #361

biona001 opened this issue Jan 7, 2021 · 7 comments

Comments

@biona001
Copy link

biona001 commented Jan 7, 2021

I created some map images following these example code. I was wondering how to save the figure in high resolution (e.g dpi=300)? I tried including dpi=300 in Layout, but it didn't do anything...

Issue #4 seems to have solved this.

@sglyon
Copy link
Member

sglyon commented Jan 11, 2021

Hi @biona001 I'm not 100%, but you'll probably have most luck checking out this repo: https://github.com/plotly/Kaleido

We use Kaleido now for exporting/savefig so any options they support should be supported here also.

@empet
Copy link

empet commented Jan 11, 2021

Hi @biona001,

For savefig you can use the same parameters as for the plotly.io.write_image: https://plotly.github.io/plotly.py-docs/generated/plotly.io.write_image.html. You can pass the image width and height in pixels, not dpi.
Note that
savefig(pl, "myplot300x300.png", width=300, height=300)
and
savefig(pl, "myplot600x600sc05.png", width=600, height=600, scale=0.5)
save the same size images, but the former preserves the default font_size , set by PlotlyJS for ticklabels, while the latter displays ticklabels of reduced size (by a factor of 0.5).
I checked this particularity for the following plot, by saving the plot pl as a png and as apdf file, as well:

using PlotlyJS
plasma = [[0.0, "#0c0786"],
         [0.1, "#40039c"],
         [0.2, "#6a00a7"],
         [0.3, "#8f0da3"],
         [0.4, "#b02a8f"],
         [0.5, "#cb4777"],
         [0.6, "#e06461"],
         [0.7, "#f2844b"],
         [0.8, "#fca635"],
         [0.9, "#fcce25"],
         [1.0, "#eff821"]];
n= 511
J = [i for i in 0:n, j in 0:n];
tr = heatmap(z=xor.(J', J), colorscale=plasma, showscale=false)
pl = plot(tr, Layout(width=400, height=450, yaxis_autorange="reversed"))

@biona001
Copy link
Author

Ok, thanks for the response.

I'm leaving this issue open for now since it doesn't seem like there is a simple solution, but feel free to close it.

@empet
Copy link

empet commented Jan 13, 2021

I searched Plotly forum https://community.plotly.com/ for how to save a plot as a pdf file with 300dpi, and found no answer, but on SO there is a solution:https://stackoverflow.com/questions/61199397/export-300dpi-tiff-of-plotly-plot-in-r.
I tried it for a map from your posted link, and it works with:

savefig(pl, "dpi300.pdf", width=8*300, height=11*300)

8.5 x 11 inches is a pdf page.

@StepanSushko
Copy link

got unsupported keyword arguments "width", "height"

@empet
Copy link

empet commented Mar 21, 2022

@StepanSushko
What version are you running? I've just checked it with Julia 1.7 and PlotlyJS.jl, v. 0.18.8:

savefig(pl, "myfig.pdf",  width=4*300, height=3*300, scale=1) # pl = Plot(....)

and got this pdf file: https://github.com/empet/Datasets/blob/master/Images/myfig.pdf.

@chelseas
Copy link

Got the unsupported keyword thing too with:

Plots v1.22.2

And

Julia Version 1.6.1
Commit 6aaedecc44 (2021-04-23 05:59 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: AMD Ryzen 7 4800H with Radeon Graphics
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, znver2)

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