Probably stupid plotting question in regards to saving figures

I do not understand why my following code does not work:

#crit_theta.jl
using Plots

deg = 5
rad = deg/360 * 3.14159
a = 0.15
α = -0.9
f(x) = ((tand(x)-tand(deg))/a)^α

plt = plot(f,
           5.1,
           15,
           title = "Bed height vs. critical angle",
           xlabel = "Critical angle θ",
           ylabel = "Dimensionless height h/d",
           xlims = (4,15),
           ylims = (0,25),
           legend = false
           )

savefig(plt,"height_v_theta.png")
~                                     

When I run this, I get the following error:

ERROR: MethodError: objects of type Tuple{Plots.Plot{Plots.GRBackend}, String} are not callable
Stacktrace:
 [1] top-level scope
   @ REPL[29]:1

If I comment out the line for savefig, everything runs fine. Furthermore if I just type plt in the repl my plot displays perfectly. I am doubly confused because I thought savefig specifically took objects of type Tuple{Plots.Plot{Plots.GRBackend}, String}…am I missing something super obvious?

1 Like

Works on my side.

height_v_theta

What version of Julia / Plots are you using?

1 Like

Good to know I’m not missing something obvious. I am running Julia 1.6.2 and my Plots package is version 1.21.3

Same version of Julia, but I am using Plots 1.22.1. They might have changed the order of the savefig arguments at some point. Can you try updating it to 1.22.1?

1 Like

sure, Ill do that right now!

That fixed it. I’ll make sure to update all my packages before I post a question next time. Thanks for the help :slight_smile:

4 Likes