Workstation Types

The layered architecture of GR and GKS allows the use of a wide variety of GUI toolkits and file formats using so-called workstations. You can select the workstation by setting the GKS_WSTYPE environment variable or by explicitly opening it using gks_openws(). These workstation types will also be used when you print the output to a file using gr_beginprint(), GR.beginprint(pathname), gr.beginprint() or mlab.savefig().

File Formats

Plugin GKS_WSTYPE File Type
built-in pdf / 102 PDF
built-in ps / 62 PS
built-in eps / 62 EPS
built-in gif / 130 GIF
movplugin mov / 120 MOV
videoplugin mp4 / 160 MP4
videoplugin webm / 161 WEBM
videoplugin ogg / 162 OGG
gsplugin bmp / 320 BMP
gsplugin jpg / jpeg / 321 JPEG
gsplugin png / 322 PNG
cairoplugin png / 140 PNG
gsplugin tif / tiff / 323 TIFF
figplugin fig / 370 FIG
svgplugin svg / 382 SVG
wmfplugin wmf / 390 WMF
htmplugin html / 430 HTML
pgfplugin pgf / 314 PGF

Both the gsplugin and the cairplugin can be used to create PNG files. If both plugins are available, the gsplugin will be used by default, but the environment variable GKS_USE_CAIRO_PNG can be set to use the cairoplugin instead.

Configuring Video Output Options

The video files generated by the videoplugin have a default resolution of 1024 x 768 pixels at 24 frames per second. You can change those values by setting the GKS_VIDEO_OPTS environment variable to one of the following values:

  • <framerate>
  • <width>x<height>
  • <width>x<height>@<framerate>

Integrations

Plugin GKS_WSTYPE Description
qtplugin 381 Qt 4
qt5plugin 381 Qt 5
gtkplugin 371 GTK+
wxplugin 380 wxWidgets
glplugin 420 OpenGL

Applications

Plugin GKS_WSTYPE Operating System
built-in 211 Linux
built-in 41 Windows
quartzplugin 400 macOS

Special Workstation Types

No Output

To use GR without generating output, you can use workstation type 100. You will still be able to explicitly write output to a file using gr_beginprint() or similar GR functions, but there will be no implicit output to an application or file.

Memory

To write an image directly to memory as 32-bit RGBA data, you can allocate the memory and then use a specially constructed filename with the format !<width>x<height>@<pointer>.mem using hexadecimal notation for the pointer, e.g. by passing it to gr_beginprint(). Once GR has finished writing the image, e.g. after calling gr_endprint(), the memory will contain the image data.

# Allocate image memory, e.g. using numpy
import numpy as np
width, height = 1920, 1080
image = np.zeros((height, width, 4), np.uint8)
pointer = image.ctypes.data

# Draw something into the memory using gr
import gr
gr.beginprint('!{}x{}@{:x}.mem'.format(width, height, pointer))
gr.polyline([0, 1], [0, 1])
gr.endprint()

# Use the image memory, e.g. using PIL/pillow
from PIL import Image
image = Image.fromarray(image, 'RGBA')
# ...
/* Allocate image memory */
int width = 1920;
int height = 1080;
unsigned char *data = malloc(height * width * 4);

/* Draw something into the memory using GR */
double x[] = {0, 1};
double y[] = {0, 1};
char filename[32];
sprintf(filename, "!%dx%d@%p.mem", width, height, data);
gr_beginprint(filename);
gr_polyline(2, x, y);
gr_endprint();

/* Use the image memory and free it afterwards */
/* ... */
free(data);