Rubyplot installation guide
Published:
Summary: Installation guide for Rubyplot.
Table of Contents
Introduction
This blog is a guide for Developer installation of Rubyplot and testing including both GR and ImageMagick backends.
Installation
P.S.- Make sure you have installed Ruby and have updated it to the latest version.
Installation steps:
- Installing GR C Framework: Follow the instructions given [here] but change the command to sudo apt-get install gr (instead of sudo apt-get install python-gr).
GR will be installed in the path :/usr/gr
- Create a symbolic link for GR in the path
/usr/local/gr
using this command:sudo ln -s /usr/gr /usr/local/gr
- Clone the Rubyplot repository using this command:
git clone https://github.com/SciRuby/rubyplot.git
- Change the current directory to Rubyplot folder by using this command:
cd rubyplot
- Now set the important environment variables by running this command:
export GRDIR="/usr/local/gr" export GKS_FONTPATH="/usr/local/gr" export RUBYPLOT_BACKEND="GR"
Alternatively you can set
GRDIR
andGKS_FONTPATH
to the path where GR is installed if it’s different.
We have set the Rubyplot backend to GR. - Replace line 3 and 4 in
ext/grruby/extconf.rb
by these lines:$CFLAGS << ' -I/usr/local/gr/include ' $LDFLAGS << ' -L/usr/local/gr/lib -lGR -lm -Wl,-rpath,/usr/local/gr/lib '
Or change it to the path where GR is present if different.
- Change lines 13 and 14 in
spec/spec_helper.rb
to this:ENV['GRDIR'] = "/usr/local/gr" ENV['GKS_FONTPATH'] = "/usr/local/gr"
Or change it to the path where GR is present if different.
- Run these commands:
sudo gem install bundler bundle install rake compile
GR backend has been setup, now we need to set up the ImageMagick backend.
- To install ImageMagick and rmagick follow the instructions [here].
- Now, we have setup both the backends and can change the backends at any time using this command:
export RUBYPLOT_BACKEND="GR" # For GR backend export RUBYPLOT_BACKEND="MAGICK" # For ImageMagick backend
Testing
Running all tests at once
To run all the tests at once, run this command in the rubyplot folder:
rspec
Running specific tests
For running specific tests follow these instructions:
- Make sure you are in the rubyplot folder.
- Change the backend to desired one by following step 10 of Installation.
- Tests related to specific plots are present in
spec/axes_spec.rb
and tests general tests are present inspec/figure_sprc.rb
. - Append
,focus:true
in front of the test(s) which you want to run, for example, the bubble plot tests are:context "#bubble!" do it "plots a single bubble plot" do @figure = Rubyplot::Figure.new axes = @figure.add_subplot! 0,0 axes.bubble! do |p| p.data [-1, 19, -4, -23], [-35, 21, 23, -4], [4.5, 1.0, 2.1, 0.9] p.label = "apples" p.color = :blue end axes.x_range = [-40, 30] axes.y_range = [-40, 25] axes.title = "simple bubble plot." end it "plots multiple bubble plots on same axes." do @figure = Rubyplot::Figure.new axes = @figure.add_subplot! 0,0 axes.bubble! do |p| p.data [-1, 19, -4, -23], [-35, 21, 23, -4], [4.5, 1.0, 2.1, 0.9] p.label = "apples" end axes.bubble! do |p| p.data [20, 30, -6, -3], [-1, 5, -27, -3], [10.3, 10.0, 20.0, 10.0] p.label = "peaches" end axes.title = "simple bubble plot." end end
Append
,focus:true
in front ofcontext "#bubble!"
if you want to run every test in the context of bubble plot.
Or append,focus:true
in front of any test which you want to run, for example, in front ofit "plots a single bubble plot"
.
An example for appended code is:context "#bubble!",focus:true do it "plots a single bubble plot",focus:true do @figure = Rubyplot::Figure.new axes = @figure.add_subplot! 0,0 axes.bubble! do |p| p.data [-1, 19, -4, -23], [-35, 21, 23, -4], [4.5, 1.0, 2.1, 0.9] p.label = "apples" p.color = :blue end axes.x_range = [-40, 30] axes.y_range = [-40, 25] axes.title = "simple bubble plot." end it "plots multiple bubble plots on same axes.",focus:true do @figure = Rubyplot::Figure.new axes = @figure.add_subplot! 0,0 axes.bubble! do |p| p.data [-1, 19, -4, -23], [-35, 21, 23, -4], [4.5, 1.0, 2.1, 0.9] p.label = "apples" end axes.bubble! do |p| p.data [20, 30, -6, -3], [-1, 5, -27, -3], [10.3, 10.0, 20.0, 10.0] p.label = "peaches" end axes.title = "simple bubble plot." end end
Append it in front of all tests which you want to run.
- Run this command:
rspec --t=focus`