GR.cr
Crystal bindings to GR framework.
GR.cr has been forked from gr-crystal by Jun Makino.
Installation
GR Installation
Official release - Linux, Mac, Windows
Set GRDIR : export GRDIR="your/path/to/gr"
OpenSUSE build service - Linux
Set GRDIR : export GRDIR="/usr/gr"
Homebrew - Mac
brew install libgr
GR.cr installation
Add the dependency to your shard.yml:
dependencies:
gr:
github: crystal-data/GR.cr
Run shards install
API Overview
libGR,libGR3,libGRM: call native functions directly.GR,GR3,GRM: call module function customized for Crystal.
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ GRM │ │ GR │ │ GR3 │
│ ┌──────────┐ │ │ ┌──────────┐ │ │ ┌──────────┐ │
│ │ LibGRM │ │ │ │ LibGR │ │ │ │ LibGR3 │ │
│ └──────────┘ │ │ └──────────┘ │ │ └──────────┘ │
└──────────────┘ └──────────────┘ └──────────────┘
GR.cr is still immature, but even in its current state, GRM can be used to create good quality figures.
Quick Start
Simple Line Plot
require "grm"
x = [1.0, 2.0, 3.0, 4.0, 5.0]
y = [1.0, 4.0, 9.0, 16.0, 25.0]
# High-level API
GRM.plot(x, y, title: "My Plot")
# Object-oriented API
plot = GRM::Plot.new
.data(x, y)
.color("red")
.title("My Plot")
.xlabel("X")
.ylabel("Y")
plot.show
plot.save("output.png")
Plot Types
require "grm"
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
GRM.plot(x, y, title: "Line Plot")
GRM.scatter(x, y, title: "Scatter Plot")
GRM.barplot(x, y, title: "Bar Chart")
GRM.histogram([1, 2, 2, 3, 3, 3, 4, 4, 5], title: "Histogram")
3D Surface Plot
require "grm"
x = [1.0, 2.0, 3.0]
y = [1.0, 2.0, 3.0]
z = [
[1.0, 4.0, 9.0],
[2.0, 8.0, 18.0],
[3.0, 12.0, 27.0]
]
plot = GRM::Plot.new
.data2d(x, y, z)
.surface
.title("3D Surface")
plot.show
Supported Features
- 2D Plots: line, scatter, barplot, histogram, stem, stairs, hexbin, polar
- 3D Plots: plot3, surface, contour, scatter3
- Output: PNG, HTML, JSON export
- API: High-level functions and object-oriented interface
Note: Multiple 2D plots in one figure do not currently work.
Usage
Please see the example directory.
With GR and GR3 modules, you can do more serious visualization. However, you may find that GR.cr is not fully implemented. In that case, please send me a pull request.
Development
Low-level bindings are automatically generated by crystal_lib.
GR.cr is a library under development, so even small improvements like fixing typos are welcome! Please feel free to send us your PR. The author is not familiar with Crystal, so it may be written in an inefficient way, and you may be able to fix it.
- Look at GR.rb and implement the missing methods!
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features
Acknowledgements
We would like to thank Josef Heinen, the creator of GR and GR.jl, Florian Rhiem, the creator of python-gr, and all GR developers.
