Introduction to GR

GR is a universal framework for cross-platform visualization applications. It offers developers a compact, portable and consistent graphics library for their programs. Applications range from publication quality 2D graphs to the representation of complex 3D scenes.


GR is essentially based on an implementation of a Graphical Kernel System (GKS) and OpenGL. As a self-contained system it can quickly and easily be integrated into existing applications (i.e. using the ctypes mechanism in Python or direct calls from Julia with ccall syntax).

The GR framework can be used in imperative programming systems or integrated into modern object-oriented systems, in particular those based on GUI toolkits. GR is characterized by its high interoperability and can be used with modern web technologies and mobile devices. The GR framework is especially suitable for real-time environments.

GR was developed by the Scientific IT-Systems group at the Peter Grünberg Institute at Forschunsgzentrum Jülich. The main development has been done by Josef Heinen who currently maintains the software.

GR3 is a software library for simple visualization of 3D scenes. It was developed by Florian Rhiem as part of his bachelor's thesis. GR3 is written in C and can also be used from Python or Julia through a wrapper module.

Getting Started

Julia

For the Julia programming language an official GR.jl package has been registered. You can add the GR framework to your Julia installation with the Pkg.add() function:

Pkg.add("GR")

Let's start with a simple example. We generate 10,000 random numbers and create a histogram. The histogram function automatically chooses an appropriate number of bins to cover the range of values in x and show the shape of the underlying distribution.

 using GR
 histogram(randn(10000))

Python

For various Linux distributions we provide .rpm and .deb packages (python-gr) using openSUSE Build Service. Your operating systems package manager will cope with package dependencies. Please follow the installation instructions for your operating system described here.

For Windows and OS X it's highly recommended to use a Python bundle, eg. Anaconda. For those systems you can download and install ready-to-use packages with a single command::

conda install -c https://conda.anaconda.org/jheinen gr

Now, the same result for the histogram example can be achieved in Python:

from numpy.random import randn
from gr.pygr.mlab import *

histogram(randn(10000))

Using GR as a backend for Matplotlib

Matplotlib is the most popular graphics library for Python. It is the workhorse plotting utility of the scientific Python world. However, depending on the field of application, the software may be reaching its limits. This is the point where the GR framework will help.

Starting with release 0.6.0 the GR framework can be used as a backend for Matplotlib and significantly improve the performance of existing Matplotlib applications, e.g.:

python artist_reference.py -dmodule://gr.matplotlib.backend_gr

With Matplotlib 1.5 you can set the backend using the MPLBACKEND environment variable::

export MPLBACKEND="module://gr.matplotlib.backend_gr"

Some of the Matplotlib examples (generated with the GR backend) are shown below. You don't have to change any line of code and, as you can see, the results match with the original.

Using GR as backend for Plots.jl

Plots is a powerful wrapper around other Julia visualization "backends", where GR seems to be one of the favorite ones. To get an impression how complex visualizations may become easier with Plots, take a look at these examples.

Notebook examples

Here you can find some interesting Jupyter notebooks written for Python ...

... or Julia kernels: