The trick is to realize that there is an internal dpi value in Plots.jl
and the actual dpi value of the saved figure. The internal value is hardcoded as 100. The actual dpi value of the saved figure is set via plots(...; dpi=DPI)
. This can be reflected in your code snippet as
using Plots
x = 0:0.01:2π;
y = cos.(x);
DPI = 600
width_inches = 3.4
width_px = width_inches * 100 # internal dpi=100
p = plot(x,y;size=(width_px, width_px), dpi=DPI)
savefig(p, "test.png")
This gives me the following png file:
Hope this helps!