GR.rb
:bar_chart: GR framework - powerful visualization library - for Ruby
Installation
GR.rb supports Ruby 2.5+.
First, install GR. Next, set environment variable GRDIR.
export GRDIR="/your/path/to/gr"
gem install ruby-gr
Quick Start
require 'gr/plot'
x = [0, 0.2, 0.4, 0.6, 0.8, 1.0]
y = [0.3, 0.5, 0.4, 0.2, 0.6, 0.7]
GR.plot(x, y)
require 'gr/plot'
x = Numo::DFloat.linspace(0, 10, 101)
y1 = Numo::NMath.sin(x)
y2 = Numo::NMath.cos(x)
GR.plot(
[x, y1, 'bo'], [x, y2, 'g*'],
title: "Multiple plot example",
xlabel: "x",
ylabel: "y",
ylim: [-1.2, 1.2],
labels: ["sin(x)", "cos(x)"],
location: 11
)
Save in PNG format.
GR.savefig("figure.png")
API Overview
There are two different approaches to plotting with GR.rb. One way is to call Matlab-like APIs. The other is to call GR/GR3 native functions. We are planning to prepare a more object-oriented interface based on GRUtils.jl in the future.
GR::Plot - A simple, matlab-style API.
require 'gr/plot'
GR.plot(x, y)
List of vailable functions. See GR.rb Wiki for details.
plot
step
plot3
polar
scatter
scatter3
stem
barplot
histogram
polarhistogram
hexbin
contour
contourf
tricont
surface
trisurf
wireframe
volume
heatmap
polarheatmap
shade
imshow
isosurface
GR - A module for calling native GR functions.
2-D Plots and common 3-D Plots.
require 'gr'
# For example
GR.(0.1, 0.9, 0.1, 0.9)
GR.setwindow(0.0, 20.0, 0.0, 20.0)
GR3 - A module for calling native GR3 functions.
Complex 3D scenes.
require 'gr3'
# For example
GR3.cameralookat(-3, 2, -2, 0, 0, 0, 0, 0, -1)
Documentation
GR Installation
Installing an official release (recommended)
Download the latest release.
Set environment variable GRDIR.
export GRDIR="your/path/to/gr"
- macOS Catalina and macOS Mojave: See the "How to open an app that hasn’t been notarized or is from an unidentified developer" section of Safely open apps on your Mac in the Apple documentation.
Using your package manager
- The third party GR packages for Mac, Linux and Windows are available (for advanced users).
- If you find any problem, please report the issue here.
Mac - Homebrew
brew install libgr
Set environment variable GRDIR.
export GRDIR=$(brew --prefix libgr)
Linux - APT Yum
packages.red-data-tools.org provides libgr-dev and libgr3-dev.
Windows - MSYS2
If you are using Rubyinstaller, pacman will automatically install mingw-w64-gr when the gem is installed.
Backend for Charty
GR.rb will be the default backend for Charty.
Contributing
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features
- Create visualization library based on GR.rb
Acknowledgements
We would like to thank Josef Heinen, the creator of GR.jl, Florian Rhiem, the creator of python-gr, and GR developers.














