Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to plot a layout in Julia, using different colours per plot?

I am trying to plot a layout in Julia env using the code below

x = 1:100
y = sin.(rand((Normal()), 100,4))
# plot
plot(x,y)
# layout
plot(x,y, layout = (4,1), color = [:red,:blue])

What I expected was a coloring of each plot with either red or blue. The result was 4 plots that had both red and blue. What am I missing?

like image 953
ouroukai Avatar asked Dec 01 '25 22:12

ouroukai


1 Answers

It is due to the dimension of color:

julia> [:red,:blue]
2-element Vector{Symbol}:
 :red
 :blue

It is reasonable to think it will apply this scheme to each 2 items of the original array. However...

julia> [:red :blue]
1×2 Matrix{Symbol}:
 :red  :blue

this will be applied each 2 columns. So it should be as follows:

julia> plot(x, y, layout=(4, 1), color=[:red :blue])
like image 186
valcarcexyz Avatar answered Dec 04 '25 19:12

valcarcexyz