-
-
Notifications
You must be signed in to change notification settings - Fork 355
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
[BUG] savefig not honoring size=() and dpi=() attributes with PlotlyJS backend #3199
Comments
pgfplotsx has the same problem with the Default sizeGR defaults to 600x400 px, while PGFPlotsX default to 914x539 px, using the following MWE using Plots, LaTeXStrings
data = rand(10)
plot(data)
savefig("size_gr.png")
pgfplotsx()
plot(data)
savefig("size_pgfplotsx.png") The result is difficult to replicate, because with random data each run can end (or not) in a different final image size for PGFPlotsX. The aspect ratio of the actual plot (everything but the legend) seems similar enough though, doing using Plots, LaTeXStrings
data = rand(10)
plot(data)
savefig("size_gr.png")
pgfplotsx()
plot(data, legend=false)
savefig("size_pgfplotsx.png") I get 600x400 px (600/400 = 1.5) for GR, as it should, and 860x546 px (860/546 = 1.575) for PGFPlotsX. So, in the ballpark. Personalized sizeThe fact that kind of tries to respect the aspect ratio can be seen again doing using Plots, LaTeXStrings
pgfplotsx()
for i in 1:30
plot(rand(10), size=(600,600))
savefig("size_pgfplotsx_" * string(i) * ".png")
end I get 30 images with varying sizes: 914x849 px (x2), 914x841 px (x1), 914x839 px (x26), 923x839 px (x1), but all close to 1:1, if it weren’t for the legend. A different run would give different results, obviously. Clearly is taking the input size, the data and then choosing the final size, but as far as I know it is not documented which algorithm is used, as to reversed it and control effectively the final size. In practice this is "solved" by trying different inputs until you get one output you like/can use. What is especially annoying is the preference for odd values making impossible to use a series of images for a video with VideoIO.jl (in the example above not a single one got an even x even value). This is maybe tangentially related to #2303, where GR produces results off by one pixel. VersionsFrom
From
|
I had this problem too. using Plots
import Plotly
plotlyjs()
y = randn(20, 4)
plt = plot(y, size=(300,400), show=true)
width, height = plt.attr[:size]
Plots.prepare_output(plt)
Plotly.savefig(Plots.plotlybase_syncplot(plt), "test.png", width=width, height=height) |
I'm trying to use PlotlyJS in Pluto, but I cannot save files using the desired resolution. I've tried the above method but it doesn't work. I'm forced to use the GR backend to save files, but it lacks the nice interactive features plotlyjs has. |
For reference, a similar workaround for PlotlyJS in Pluto is import PlotlyJS
width, height = plt.attr[:size]
Plots.prepare_output(plt)
PlotlyJS.savefig(Plots.plotlyjs_syncplot(plt), "plot.pdf", width=width, height=height) |
This problem definitely occurs using the Plotly backend in Plots.jl . Unfortunately the savefig exported in Plots.jl does NOT have width and height arguments. I haven't yet tried @ranocha solution. This is an important issue for automating and creating plots for documents. I hope that the Plots.jl crew can remedy this. Interestingly, if you save the figure directly from within the vscode Julia plots pane, the svg file will have the correct sizing. |
This is still a problem for my setup, but I can also not use the work proposed by @ranocha because Julia Version 1.9.2 Plotly v0.4.1
Results in
Any suggestion or alternative work around would be greatly appreciated. |
It's now called |
I think this has not been reported before. I found that, when using the PlotlyJS backend, the
size
anddpi
kwargs seem to be ingored and thus don't produce the expected results.Details
size
, with the following MWE the plot shows up correctly in the plot pane (I use vscode, if that's important), but when I callsavefig
, the created image will always have a resolution of 700 * 500, as if thesize
keyword was not there. This is particularly annoying since obviously I need the plots to have a certain non-standard aspect ratio.dpi
, this value seems to be ignored at all, since the plot that shows up in the plot pane has the same size as it has when omitting thedpi
kwarg (contrary to GR, where the size of the plot in the plot pane will adjust accordingly (which I don't find helpful, but that's another topic 😅 )) and the resulting image file always ends up having the standard resolution of 700 * 500.Backends
This bug occurs on ( insert
x
below )Versions
Plots.jl version: v1.9.1
Backend version (
]st -m
): PlotlyJS v0.14.0Output of
versioninfo()
:The text was updated successfully, but these errors were encountered: