fsdnav
fsdnav

Reputation: 49

Where is the missing comma or () in this Julia histogram?

Downloaded Julia 15 min ago and thought I would play around.

I keep getting this error: syntax: missing comma or ) in argument list

using Pkg
Pkg.add("CSV")
Pkg.add("DataFrames")
Pkg.add("Plots")

using CSV
using DataFrames
using Plots
 
iris = CSV.read("julia/iris.csv", normalizenames = true)

histogram(
    iris.sepal_length, 
    title = "This is my first Julia graph", 
    label = "size", 
    xlabel "X", 
    ylabel = "Y"
)

Have restarted kernel and written like matplot and seaborne, still getting error.

Also:

Updating registry at ~/.julia/registries/General Resolving package versions... No Changes to ~/.julia/environments/v1.5/Project.toml No Changes to ~/.julia/environments/v1.5/Manifest.toml Resolving package versions... No Changes to ~/.julia/environments/v1.5/Project.toml No Changes to ~/.julia/environments/v1.5/Manifest.toml Resolving package versions... No Changes to ~/.julia/environments/v1.5/Project.toml No Changes to ~/.julia/environments/v1.5/Manifest.toml

Seems fine. Any ideas? Thanks guys!

#Edit: Also, this code:

p1 = scatter(iris.petal_length)
p2 = histogram(iris.petal_width)
p3 = histogram(iris.sepal_length)
p4 = scatter(iris.sepal_width)

plot = (p1, p2, p3, p4, layout = (2, 2), legend = false)

print(plot)

returns: (p1 = Plot{Plots.GRBackend() n=1}, p2 = Plot{Plots.GRBackend() n=1}, p3 = Plot{Plots.GRBackend() n=1}, p4 = Plot{Plots.GRBackend() n=1}, layout = (2, 2), legend = false)

??????????

Upvotes: 3

Views: 382

Answers (1)

Nils Gudat
Nils Gudat

Reputation: 13800

You first error is:

xlabel "X", 

which should be

xlabel = "X",

Your second error is that you are creating your final plot by putting p1 to p4 into a NamedTuple, rather than plotting them. You should be doing:

plot(p1, p2, p3, p4, layout = (2, 2), legend = false)

i.e. call the plot function with your subplots as arguments. Instead you are doing:

(p1, p2, p3, p4, layout = (2, 2), legend = false)

which is the Julia syntax for creating a NamedTuple, compare:

julia> (a = 1, b = "letters", c = false)
(a = 1, b = "letters", c = false)

julia> typeof(ans)
NamedTuple{(:a, :b, :c),Tuple{Int64,String,Bool}}

Upvotes: 3

Related Questions