I like the syntax of plotting using Gadfly, but it is relatively far from my experience with plotting with Matlab and Plots.
I wonder if there is an easy way how to control the colors and labels in the following example:
using Gadfly, ColorSchemes
p = plot()
for ii = 1:10
l = layer(y = rand(10), Geom.line)
using Cairo, Fontconfig
I get this output
To change the color, just add
color=[ii] to your layer (note
ii can be a string).
Gadfly can plot wide-format data (i.e. data in a matrix) too, see examples in Gadfly docs. In your example, if your data was in a matrix, when plotting in wide-format Gadfly puts 10 lines in 1 layer (and colors them), whereas your example above has 1 line in 10 layers (layers are computationally more expensive than lines).
That was easy, thank you very much.
You are right with the wide-format, but in my real use case the number of data points will vary in each iteration.
Is there an easy way how to change the color scheme. I have found only examples for continuous scale
cpalette(p) = get(ColorSchemes.viridis, p)
p1 = plot(D, y=:y, x=:x, color=0:29, Geom.bar,
Maybe like this?
using ColorSchemes: viridis
palette = [ get(viridis, i) for i in range(0, length=10, stop=1) ]
p = plot()
for i in 1:10
l = layer(y = rand(10), Geom.line, color=[palette[i]])
push!(p, Guide.manual_color_key("", ["label $i" for i in 1:10] , [palette...]))
Here’s a plot that combines an example of plotting a “vector of vectors” (of different lengths), and an example of a viridis discrete colorscheme:
import ColorSchemes as cs
ys = [cumsum(randn(rand(10:20))) for _ in 1:5]
plot(ys, x=Row.index, y=Col.value, color=Col.index, Geom.line,
Scale.color_discrete(n->get(cs.viridis, range(0, 1, length=n))))
The “vector of vectors” bit assumes that the x’s are the same, we should investigate handling a “vector of matrices with x & y”.
Sorry to ask you again. Is there way how to set the background colour of colorkey?
I would like to place it inside the plot.
Its an open issue and would be easy to add, but time is against me atm
Thank you for answers and good work done on Gadfly