Julia plot not saved properly

I am using Plots to create the XY plot and then saving it in the pdf format. But the text in the ylabel is not saved properly. The power of the 10 is not saved and the number appears like 1.0X10 instead of 1.0X10^-8. Below is the part of the code I am using for plotting. x and y are arrays of the same size.

color=[:red :blue]

p = plot(x,y,lw = 3,
         ylabel = "L2 Norm", yscale = :log10,
         xlabel="Iteration count", #xlims=(0,maximum(iter_hist)+1),
         grid=(:none),
         label=["rms" "rms/rms\$_0\$"], color=color)
         
savefig(p,"gs_residual.png")

Below is the saved .png file. As you can see, the numbers on the x-axis are not printed correctly and the exponent is missing. Even if I save the figure in .pdf format I get the same results.

gs_residual

Thank you. Regards,

Hi @surajp92, welcome to the forums! Could you please post the code (or ideally a minimum working example) that reproduces your problem? If you provide code that people can run that reproduces your problem, and maybe post a screenshot of the plot that doesn’t look the way you intend, it will enable people to help you more easily. At the moment, you haven’t really provide enough detail to diagnose the issue.

Please also take a look at this post for information on how to format the code in your post and other useful information

1 Like

Thanks for the edit - much clearer! I haven’t seen that before, and it’s especially weird that it looks fine on the y axis. Are you using the default GR back end?

I am using Plot package (Home · Plots). Yeah, on Y-axis we get correct number. But for some reason, the exponent is missing in x-axis numbers. Is it different than the GR package?
Thank you.

Plots.jl doesn’t actually do any drawing of plots - its a common API to a number of different backends. GR is the default though, so if you didn’t intentionally change it, that’s what you’re using.

I don’t have a good explanation - it might be worth trying to do the same thing with GR.jl, and then open an issue there if you see the same behavior, or on Plots.jl if you don’t.

Which backend are you using? Try:

plotly()
color=[:red :blue]

p = plot(x,y,lw = 3,
         ylabel = "L2 Norm", yscale = :log10,
         xlabel="Iteration count", #xlims=(0,maximum(iter_hist)+1),
         grid=(:none),
         label=["rms" "rms/rms\$_0\$"], color=color)
         
savefig(p,"gs_residual.png")

and see what happens? It could be that your backend is not rendering the Unicode characters correctly.

using plotly() did not helped. I am using PyPlot which offers matplotlib interface for Julia.
Thank you all for your help.

If you provide an example of how you generate x and y, it will be easier for others to test and compare what it looks like on other computers. On my computer (Windows 10, Julia v. 1.1.1), it looks fine:

julia> x = range(pi,3pi,length=100);
julia> y = hcat(2 .+ sin.(x), 2 .+ cos.(x));
julia> plot(x,y,lc=[:red :blue], xscale=:log10, yscale=:log10,label=["2+sin(x)" "2+cos(x)"])

leading to:
image

My data are surely different from yours,

I think I found the problem. I was running the code directly in Atom ide. If I run it from the terminal then I get correct xticks values with the exponent. Also, I am setting the global font in the beginning of my code

font = Plots.font("Times New Roman", 18)

Thank you all for your help.