juliajulia-plots

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?


Solution

  • 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])