Issue with saving plot as pdf

yerror bar in plot generated on vs code shows different level of thickness for yerror bar in comparision to saved pdf file.

In vs code :

In pdf format: (you can notice thickness has increased)

In png format (it looks fine in this format)

Please provide a MWE and information on the platform you are running on.

using VS code and Julia version 1.9.3

#MWE

using StatsPlots, CSV, Distributions, Measures, DataFrames

fake_norm_data = DataFrame(V = repeat(["A", "B", "C", "D", "E", "F", "G","H", "I"], inner = 51, outer = 1), 
X =  repeat(["a", "b", "c", "d", "d", "f", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s"], inner = 1, outer = 27),
Z =  repeat(["2M", "3M", "5M"] , outer = 9, inner = 17), 
Y =  rand(0:0.1:2, 459),
W = rand(0:0.01:0.1, 459))


p1 = groupedbar(fake_norm_data.X[1:51], fake_norm_data.Y[1:51], group = fake_norm_data.Z[1:51], yerror = fake_norm_data.W[1:51], msw = 0.6, alpha = 0.9, xrotation = 45,  title = "Target - A",  bottom_margin = 7mm, left_margin=5mm, legend = :outertopright)

p2 = groupedbar(fake_norm_data.X[52:102], fake_norm_data.Y[52:102], group = fake_norm_data.Z[52:102], yerror = fake_norm_data.W[52:102], msw = 0.6, alpha = 0.9, xrotation = 45,  title = "Target - B",  bottom_margin = 7mm, left_margin=5mm, legend = :outertopright)

p3 = groupedbar(fake_norm_data.X[103:153], fake_norm_data.Y[103:153], group = fake_norm_data.Z[103:153], yerror = fake_norm_data.W[103:153], msw = 0.6, alpha = 0.9, xrotation = 45,  title = "Target - C",  bottom_margin = 7mm, left_margin=5mm, legend = :outertopright)

p4 = groupedbar(fake_norm_data.X[154:204], fake_norm_data.Y[154:204], group = fake_norm_data.Z[154:204], yerror = fake_norm_data.W[154:204], msw = 0.6, alpha = 0.9, xrotation = 45,  title = "Target - D",  bottom_margin = 7mm, left_margin=5mm, legend = :outertopright)

p5 = groupedbar(fake_norm_data.X[205:255], fake_norm_data.Y[205:255], group = fake_norm_data.Z[205:255], yerror = fake_norm_data.W[205:255], msw = 0.6, alpha = 0.9, xrotation = 45,  title = "Target - E", bottom_margin = 7mm, left_margin=5mm, legend = :outertopright)

p6 = groupedbar(fake_norm_data.X[256:306], fake_norm_data.Y[256:306], group = fake_norm_data.Z[256:306], yerror = fake_norm_data.W[256:306], msw = 0.6, alpha = 0.9, xrotation = 45,  title = "Target - F",  bottom_margin = 7mm, left_margin=5mm, legend = :outertopright)

p7 = groupedbar(fake_norm_data.X[307:357], fake_norm_data.Y[307:357], group = fake_norm_data.Z[307:357], yerror = fake_norm_data.W[307:357], msw = 0.6, alpha = 0.9, xrotation = 45,  title = "Target - G",  bottom_margin = 7mm, left_margin=5mm, legend = :outertopright)

p8 = groupedbar(fake_norm_data.X[358:408], fake_norm_data.Y[358:408], group = fake_norm_data.Z[358:408], yerror = fake_norm_data.W[358:408], msw = 0.6, alpha = 0.9, xrotation = 45,  title = "Target - H",  bottom_margin = 7mm, left_margin=5mm, legend = :outertopright)

p9 = groupedbar(fake_norm_data.X[409:459], fake_norm_data.Y[409:459], group = fake_norm_data.Z[409:459], yerror = fake_norm_data.W[409:459], msw = 0.6, alpha = 0.9, xrotation = 45,  title = "Target - I",  bottom_margin = 7mm, left_margin=5mm, legend = :outertopright)


plot( p1, p2, p3, p4, p5, p6, p7, p8, p9, layout = (3,3), size = (1600, 1200), left_margin=10mm, dpi = 300)

savefig("/path/dummy1_plot.png")
savefig("/path/dummy2_plot.pdf")

The default backend gr() doesn’t support the dpi attribute, so I am guessing it just ignores it and we get a weird looking plot.

Using pythonplot() as backend worked and I got:

NB, using inspectdr(), which also supports dpi, gets the error bars correctly, but messes up the grid and sizes:

For the record,

savefig("/path/dummy2_plot.svg")

and then manually to pdf worked fine as well (but I specified the dpi manually), so I am assuming the problem is in passing the pdf settings.

1 Like