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.
In [1]:
require 'nyaplot'
Out[1]:
Out[1]:
Use Nyaplot::Colors#lists to show the lists of prepared colorsets.
In [2]:
Nyaplot::Colors.lists
Out[2]:
Try some of those colorsets.
In [3]:
Nyaplot::Colors.Pastel2
Out[3]:
In [4]:
Nyaplot::Colors.jet
Out[4]:
In [5]:
Nyaplot::Colors.GnBu
Out[5]:
In [6]:
Nyaplot::Colors.binary
Out[6]:
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.
In [7]:
Nyaplot::Colors.seq
Out[7]:
In [8]:
Nyaplot::Colors.div
Out[8]:
In [9]:
Nyaplot::Colors.qual
Out[9]:
Those methods can have one argument to specify required number of colors.
In [10]:
Nyaplot::Colors.seq(3)
Out[10]:
In [11]:
Nyaplot::Colors.Spectral(11)
Out[11]:
Use Nyaplot::Color to try your favorite color (Credits: fatalflaws)
In [12]:
Nyaplot::Color.new(["#DEDEDE", "#ACACAC", "#1F141C", "#4A173D", "#8C547E"])
Out[12]:
Then try those colors in some plots.
In [13]:
plot = Nyaplot::Plot.new
bar = plot.add(:bar, ['Persian', 'Maine Coon', 'American Shorthair'], [10,20,30])
plot.show
Out[13]:
In [14]:
colors = Nyaplot::Colors.qual(3)
Out[14]:
In [15]:
bar.color(colors)
plot.show
Out[15]:
In [18]:
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
Out[18]:
In [39]:
colors = Nyaplot::Colors.GnBu
Out[39]:
In [41]:
hm.color(colors)
plot2.show
Out[41]: