Open AsgerHB opened 1 year ago
see the discussion in https://github.com/JuliaPlots/Plots.jl/issues/2655
I find myself rescaling them manually
How do you rescale manually? I am facing the same issue. I am using Julia for the figures in a textbook and I must increase the legendfontsize
, but then the legend marker size shrinks to be far too small. It is quite unexpected that legendfontsize
would affect the legend marker size.
using Plots
p1 = plot(1:4, marker=:circle, markersize=9)
p2 = plot(1:4, marker=:circle, markersize=9, legendfontsize=16)
I export them in SVG, making sure to always use the svg() function for concistency. (They turn out slightly different when output from a Pluto Notebook.) Then I open the file in Inkscape to make my changes. Optionally I use the Inkscape command line to export the finished svgs to other formats.
fre. d. 16. jun. 2023 14.52 skrev Jeff Fessler @.***>:
I find myself rescaling them manually
How do you rescale manually? I am facing the same issue. I am using Julia for the figures in a textbook and I must increase the legendfontsize, but then the legend marker size shrinks to be far too small. It is quite unexpected that legendfontsize would affect the legend marker size.
using Plots p1 = plot(1:4, marker=:circle, markersize=9) p2 = plot(1:4, marker=:circle, markersize=9, legendfontsize=16)
[image: Screenshot 2023-06-16 at 8 50 44 AM] https://user-images.githubusercontent.com/10170422/246421074-7665ebab-5595-4500-ab25-2f376a6239ff.png [image: Screenshot 2023-06-16 at 8 51 00 AM] https://user-images.githubusercontent.com/10170422/246421107-2bacd406-6641-4775-86cf-ec130d9b65d4.png
— Reply to this email directly, view it on GitHub https://github.com/JuliaPlots/Plots.jl/issues/4621#issuecomment-1594629327, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACUBQRWT22D265O4W3QHYLLXLRJKDANCNFSM6AAAAAATQ6O6Q4 . You are receiving this because you authored the thread.Message ID: @.***>
I export them in SVG
Thanks for the tip. I am also making many plots using Literate for online documentation, so there is no chance to export/tweak there. Hopefully someday we will get legendmarkersize
per #2655!
I saw that the legend items may have some tags or IDs in common that might be bulk-edited by changing the SVG code. I didn't pursue this, though. By making sure I had the right panels open in Inkscape, I could do an edit in less than 5 seconds per figure by opening them all in separate editors and closing them when the edit is done.
fre. d. 16. jun. 2023 16.45 skrev Jeff Fessler @.***>:
I export them in SVG
Thanks for the tip. I am also making many plots using Literate for online documentation, so there is no chance to export/tweak there. Hopefully someday we will get legendmarkersize per #2655 https://github.com/JuliaPlots/Plots.jl/issues/2655!
— Reply to this email directly, view it on GitHub https://github.com/JuliaPlots/Plots.jl/issues/4621#issuecomment-1594814241, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACUBQRSYEJU3LETHTLHGJG3XLRWSPANCNFSM6AAAAAATQ6O6Q4 . You are receiving this because you authored the thread.Message ID: @.***>
A fairly stupid workaround is to define a custom marker that is a scaled version of the desired marker. Custom markers can be made with the Shape() function from a polygon (see https://github.com/JuliaPlots/Plots.jl/issues/45).
MWE for circles:
using Plots
small = Shape([0.5.*i for i in Plots.partialcircle(0, 2π)])
big = Shape([2.0.*i for i in Plots.partialcircle(0, 2π)])
scatter(rand(10), label="normal", size=(400,300))
scatter!(rand(10), label="big", shape=big)
scatter!(rand(10), label="small", shape=small)
savefig("img/mwe-markersize-legend.png")
There's probably a more intelligent way to draw a circle than creating a partial circle that is 0% partial, but, hey, it works.
Rescaling only the symbols in the legend but not in the figure would require manually setting the markersize and markerstrokewidth arguments to compensate for the scaled shape, so that's not ideal. It does work as a workaround as well, though.
It is nice to learn about Shape
-- thanks! That approach helps somewhat for scatter
, though there is still some mismatch between the size in the plot and the legend and legendfontsize
still affects the legend marker size. Sadly using Shape
still does not help solve my issue for plot
where there is dramatic mismatch.
using Plots
shape = Shape([2 .* i for i in Plots.partialcircle(0, 2π)])
data = 1:4
p1 = scatter(data; shape, title="p1")
p2 = scatter(data; shape, legendfontsize=16, title="p2")
p3 = plot(data; shape, title="p3", color=:red)
p4 = plot(data; shape, legendfontsize=16, title="p4", color=:red)
plot(p1, p2, p3, p4, size=(600,600))
Details
Manually setting marker and line sizes, and then setting plot size, causes the legend to draw marker at the wrong size. In this example, it becomes impossible to see the marker. (I find myself rescaling them manually for every figure I export)
Backends
This bug occurs on ( insert
x
below )Versions
Plots.jl version: 1.38.0 Backend version (
]st -m <backend(s)>
): GR v0.71.2 Output ofversioninfo()
: