Nyaplot has an interface to various prepared colorsets. All of those colorsets are provided by Colorbrewer that is licensed under Apache License Version 2.0.
require 'nyaplot'
true
Use Nyaplot::Colors#lists to show the lists of prepared colorsets.
Nyaplot::Colors.lists
["Spectral", "RdYlGn", "RdBu", "PiYG", "PRGn", "RdYlBu", "BrBG", "RdGy", "PuOr", "Set2", "Accent", "Set1", "Set3", "Dark2", "Paired", "Pastel2", "Pastel1", "OrRd", "PuBu", "BuPu", "Oranges", "BuGn", "YlOrBr", "YlGn", "Reds", "RdPu", "Greens", "YlGnBu", "Purples", "GnBu", "Greys", "YlOrRd", "PuRd", "Blues", "PuBuGn"]
Try some of those colorsets.
Nyaplot::Colors.Pastel2
rgb(179,226,205) | rgb(253,205,172) | rgb(203,213,232) | rgb(244,202,228) | rgb(230,245,201) | rgb(255,242,174) | rgb(241,226,204) | rgb(204,204,204) |
---|---|---|---|---|---|---|---|
Nyaplot::Colors.jet
rgb(215,48,39) | rgb(244,109,67) | rgb(253,174,97) | rgb(254,224,144) | rgb(255,255,191) | rgb(224,243,248) | rgb(171,217,233) | rgb(116,173,209) | rgb(69,117,180) |
---|---|---|---|---|---|---|---|---|
Nyaplot::Colors.GnBu
rgb(247,252,240) | rgb(224,243,219) | rgb(204,235,197) | rgb(168,221,181) | rgb(123,204,196) | rgb(78,179,211) | rgb(43,140,190) | rgb(8,104,172) | rgb(8,64,129) |
---|---|---|---|---|---|---|---|---|
Nyaplot::Colors.binary
rgb(255,255,255) | rgb(240,240,240) | rgb(217,217,217) | rgb(189,189,189) | rgb(150,150,150) | rgb(115,115,115) | rgb(82,82,82) | rgb(37,37,37) | rgb(0,0,0) |
---|---|---|---|---|---|---|---|---|
Nyaplot::Colors#seq return random colors that is suitable for sequential data. Similarly, Nyaplot::Colors#div returns colors for diverging data, and Nyaplot::Colors#qual is for qualitative data.
Nyaplot::Colors.seq
rgb(255,245,235) | rgb(254,230,206) | rgb(253,208,162) | rgb(253,174,107) | rgb(253,141,60) | rgb(241,105,19) | rgb(217,72,1) | rgb(166,54,3) | rgb(127,39,4) |
---|---|---|---|---|---|---|---|---|
Nyaplot::Colors.div
rgb(213,62,79) | rgb(244,109,67) | rgb(253,174,97) | rgb(254,224,139) | rgb(255,255,191) | rgb(230,245,152) | rgb(171,221,164) | rgb(102,194,165) | rgb(50,136,189) |
---|---|---|---|---|---|---|---|---|
Nyaplot::Colors.qual
rgb(166,206,227) | rgb(31,120,180) | rgb(178,223,138) | rgb(51,160,44) | rgb(251,154,153) | rgb(227,26,28) | rgb(253,191,111) | rgb(255,127,0) | rgb(202,178,214) |
---|---|---|---|---|---|---|---|---|
Those methods can have one argument to specify required number of colors.
Nyaplot::Colors.seq(3)
rgb(224,243,219) | rgb(168,221,181) | rgb(67,162,202) |
---|---|---|
Nyaplot::Colors.Spectral(11)
rgb(158,1,66) | rgb(213,62,79) | rgb(244,109,67) | rgb(253,174,97) | rgb(254,224,139) | rgb(255,255,191) | rgb(230,245,152) | rgb(171,221,164) | rgb(102,194,165) | rgb(50,136,189) | rgb(94,79,162) |
---|---|---|---|---|---|---|---|---|---|---|
Use Nyaplot::Color to try your favorite color (Credits: fatalflaws)
Nyaplot::Color.new(["#DEDEDE", "#ACACAC", "#1F141C", "#4A173D", "#8C547E"])
#DEDEDE | #ACACAC | #1F141C | #4A173D | #8C547E |
---|---|---|---|---|
Then try those colors in some plots.
plot = Nyaplot::Plot.new
bar = plot.add(:bar, ['Persian', 'Maine Coon', 'American Shorthair'], [10,20,30])
plot.show
colors = Nyaplot::Colors.qual(3)
rgb(179,226,205) | rgb(253,205,172) | rgb(203,213,232) |
---|---|---|
bar.color(colors)
plot.show
x=[]; y=[]; fill=[]
-5.step(5, 1) do |i|
-5.step(5, 1) do |j|
x.push(i)
y.push(j)
val = Math.sin(Math.sqrt(i*i+j*j))/Math.sqrt(i*i+j*j)
fill.push((val.nan? ? 0 : val))
end
end
plot2 = Nyaplot::Plot.new
hm = plot2.add(:heatmap, x, y, fill)
hm.width(1)
hm.height(1)
plot2.legend(true)
plot2.show
colors = Nyaplot::Colors.GnBu
rgb(247,252,240) | rgb(224,243,219) | rgb(204,235,197) | rgb(168,221,181) | rgb(123,204,196) | rgb(78,179,211) | rgb(43,140,190) | rgb(8,104,172) | rgb(8,64,129) |
---|---|---|---|---|---|---|---|---|
hm.color(colors)
plot2.show