PlotlyJS.jl icon indicating copy to clipboard operation
PlotlyJS.jl copied to clipboard

The Output of `savefig()` Does Not Use the Layout Dimensions

Open RoyiAvital opened this issue 1 year ago • 6 comments

I create a simple graph with where I set the following layout:

oLayout = Layout(title = "Localization by Range Measurements: Scenario", width = 600, height = 600, 
                xaxis_range = [0, tuGridSize[1]], yaxis_range = [0, tuGridSize[2]], xaxis_title = 'x', yaxis_title = 'y',
                hovermode = "closest", margin = attr(l = 50, r = 50, b = 50, t = 50, pad = 0),
                legend = attr(x = 0.025, y = 0.975), shapes = oShp);
hP = Plot([oTr1, oTr2, oTr3, oTr4], oLayout);
display(hP);

When I save the figure, using savefig(hP, "MyFile.png"); the output neither honor the layout aspect ratio nor the pixels dimension.

Yet documentation says:

image

I'd assume it would take the values from layout.

RoyiAvital avatar Nov 14 '24 13:11 RoyiAvital

@RoyiAvital Yes, when you save a plot, set always width, height from layout or not, and scale=1. plotly.py saves a fig as an image of size (width, height) set in Layout, but unfortunately, PlotlyJS doesn't do it.

empet avatar Nov 14 '24 15:11 empet

So maybe documentation should note that the output dimensions are set by a pre defined values and not by the p provided.
Currently the documentation is ambiguous.

RoyiAvital avatar Nov 14 '24 15:11 RoyiAvital

For now, what I use is:

savefig(hP, figFileNme; width = hP.layout[:width], height = hP.layout[:height]);

RoyiAvital avatar Apr 19 '25 14:04 RoyiAvital

@RoyiAvital PR #494 updated the docstring: https://juliaplots.org/PlotlyJS.jl/stable/manipulating_plots/#PlotlyJS.savefig Do you think is this enough or do we need to be more specific?

jd-foster avatar Aug 07 '25 04:08 jd-foster

@jd-foster , I think the documentation is good. I am more concerned with the defaults. Why not take the dimensions of the figure? Or at least preserve its aspect?

RoyiAvital avatar Aug 07 '25 04:08 RoyiAvital

Yes, I see your point.

jd-foster avatar Aug 07 '25 05:08 jd-foster