This notebook is written to demonstrate Nyaplot. Nyaplot is an interactive plots generator for Ruby users. It can create various types of plots, from basic ones like scatter or line, to more practical ones like 3D charts and Map visualization. This tutorial will introduce the basic use of Nyaplot.
In [1]:
require 'nyaplot'
Out[1]:
Out[1]:
Let's make some diagrams with Nyaplot. The code shown below is the minimal code to create bar chart.
In [2]:
plot = Nyaplot::Plot.new
bar = plot.add(:bar, ['Persian', 'Maine Coon', 'American Shorthair'], [10,20,30])
Out[2]:
That's all. Plot will appear on the notebook using Nyaplot::Plot#show
.
In [3]:
plot.show
Out[3]:
That's looks good, but I noticed that x and y labels have no sence. So fix them to be correct name.
In [4]:
plot.x_label("Species")
plot.y_label("Number")
plot.show
Out[4]:
Good. Nyaplot::Plot has various options except x_label
and y_label
, and you can find them by reading documents and some other notebooks.
Next the color is not so pretty, so let's try to change colors. Nyaplot has various default colorset and it's quite easy to find your favorite one.
In [5]:
colors = Nyaplot::Colors.qual
Out[5]:
Nyaplot::Colors#qual
finds random colorset for qualitative data and it may be usable when creating bar chart or scatter. To leran more about Nyaplot::Colors
, visit Tutorial3.
Then fill bar charts in the selected color.
In [6]:
bar.color(colors)
plot.show
Out[6]:
The example above, I prepared array and use Nyaplot::Plot.add
to add bar chart to the plot. But Nyaplot has more useful API.
Let's make the same plot using Nyaplot::DataFrame
.
In [10]:
df = Nyaplot::DataFrame.new({species: ['Persian', 'Maine Coon', 'American Shorthair'], number: [10,20,30]})
Out[10]:
Use Nyaplot::Plot#add_with_df
instead of #add
to create plot from DataFrame.
In [11]:
plot2 = Nyaplot::Plot.new
plot2.add_with_df(df, :bar, :species, :number) # x-> column :species, y-> column :number
plot2.show
Out[11]:
DataFrame is useful when you create more complicated plots. Go to Tutorial2.
This tutorial was written by Naoki Nishida, as a part of products in GSoC 2014.