module GR

OverView of GR.rb

+--------------------+  +--------------------+
| GR module          |  | GR3 module         |
| +----------------+ |  | +----------------+ |
| | GR::FFI        | |  | | GR3::FFI       | |
| | +   libGR.so   | |  | | +    libGR3.so | |
| +----------------+ |  | +----------------+ |
|   | define_method  |  |   | define_method  |
| +----------------+ |  | +----------------+ |
| | | GR::GRBase   | |  | | | GR3::GR3Base | |
| | v  (Pri^ate)   | |  | | v  (Pri^ate)   | |
| +++--------------+ |  | +++--------------+ |
|  | Extend          |  |  | Extend          |
|  v                 |  |  v       +-------+ |
|      +-----------+ |  |          | Check | |
|      | GR::Plot  | |  |       <--+ Error | |
|      +-----------+ |  |          +-------+ |
+--------------------+  +----------+---------+
          ^                        ^
          |  +------------------+  |
   Extend |  | GRCommons module |  | Extend
          |  | +--------------+ |  |
          |  | |    Fiddley   | |  |
          |  | +--------------+ |  |
          |  | +--------------+ |  |
          +----+ CommonUtils  +----+
          |  | +--------------+ |  |
          |  | +--------------+ |  |
          +----+    Version   +----+
          |  | +--------------+ |
          |  | +--------------+ |
          +----+JupyterSupport| |
             | +--------------+ |
             +------------------+

(You can edit the above AA diagram with asciiflow.com/)

Fiddley is Ruby-FFI compatible API layer for Fiddle.

The GR module works without Numo::Narrray. GR3 and GR::Plot depends on numo-narray.

This is a procedural interface to the GR plotting library, github.com/sciapp/gr

Constants

ASF_BUNDLED
ASF_INDIVIDUAL
CLIP
COLORMAP_AFMHOT
COLORMAP_AUTUMN
COLORMAP_BLUESCALE
COLORMAP_BONE
COLORMAP_BRG
COLORMAP_BROWNSCALE
COLORMAP_BWR
COLORMAP_CMRMAP
COLORMAP_COOL
COLORMAP_COOLWARM
COLORMAP_COPPER
COLORMAP_CUBEHELIX
COLORMAP_CYANSCALE
COLORMAP_FLAME
COLORMAP_GEOLOGIC
COLORMAP_GIST_EARTH
COLORMAP_GIST_HEAT
COLORMAP_GIST_NCAR
COLORMAP_GIST_RAINBOW
COLORMAP_GIST_STERN
COLORMAP_GLOWING
COLORMAP_GNUPLOT
COLORMAP_GNUPLOT2
COLORMAP_GRAY
COLORMAP_GRAYSCALE
COLORMAP_GREENSCALE
COLORMAP_HOT
COLORMAP_HSV
COLORMAP_INFERNO
COLORMAP_JET
COLORMAP_MAGENTASCALE
COLORMAP_MAGMA
COLORMAP_OCEAN
COLORMAP_PILATUS
COLORMAP_PINK
COLORMAP_PLASMA
COLORMAP_RAINBOW
COLORMAP_RAINBOWLIKE
COLORMAP_REDSCALE
COLORMAP_SEISMIC
COLORMAP_SPECTRAL
COLORMAP_SPRING
COLORMAP_SUMMER
COLORMAP_TEMPERATURE
COLORMAP_TERRAIN
COLORMAP_UNIFORM
COLORMAP_VIRIDIS
COLORMAP_WINTER
COORDINATES_NDC
COORDINATES_WC
DOWNSAMPLE_HORIZONTAL_DEFAULT
DOWNSAMPLE_HORIZONTAL_LANCZOS
DOWNSAMPLE_HORIZONTAL_LINEAR
DOWNSAMPLE_HORIZONTAL_NEAREST
DOWNSAMPLE_VERTICAL_DEFAULT
DOWNSAMPLE_VERTICAL_LANCZOS
DOWNSAMPLE_VERTICAL_LINEAR
DOWNSAMPLE_VERTICAL_NEAREST
ENCODING_LATIN1
ENCODING_UTF8
FONT_AVANTGARDE_BOOK
FONT_AVANTGARDE_BOOKOBLIQUE
FONT_AVANTGARDE_DEMI
FONT_AVANTGARDE_DEMIOBLIQUE
FONT_BOOKMAN_DEMI
FONT_BOOKMAN_DEMIITALIC
FONT_BOOKMAN_LIGHT
FONT_BOOKMAN_LIGHTITALIC
FONT_COURIER
FONT_COURIER_BOLD
FONT_COURIER_BOLDOBLIQUE
FONT_COURIER_OBLIQUE
FONT_HELVETICA
FONT_HELVETICA_BOLD
FONT_HELVETICA_BOLDOBLIQUE
FONT_HELVETICA_OBLIQUE
FONT_NEWCENTURYSCHLBK_BOLD
FONT_NEWCENTURYSCHLBK_BOLDITALIC
FONT_NEWCENTURYSCHLBK_ITALIC
FONT_NEWCENTURYSCHLBK_ROMAN
FONT_PALATINO_BOLD
FONT_PALATINO_BOLDITALIC
FONT_PALATINO_ITALIC
FONT_PALATINO_ROMAN
FONT_SYMBOL
FONT_TIMES_BOLD
FONT_TIMES_BOLDITALIC
FONT_TIMES_ITALIC
FONT_TIMES_ROMAN
FONT_ZAPFCHANCERY_MEDIUMITALIC
FONT_ZAPFDINGBATS
GDP_DRAW_LINES
GDP_DRAW_MARKERS
GDP_DRAW_PATH
INTSTYLE_HATCH
INTSTYLE_HOLLOW
INTSTYLE_PATTERN
INTSTYLE_SOLID
LINETYPE_DASHED
LINETYPE_DASHED_DOTTED
LINETYPE_DASH_2_DOT
LINETYPE_DASH_3_DOT
LINETYPE_DOTTED
LINETYPE_DOUBLE_DOT
LINETYPE_LONG_DASH
LINETYPE_LONG_SHORT_DASH
LINETYPE_SOLID
LINETYPE_SPACED_DASH
LINETYPE_SPACED_DOT
LINETYPE_TRIPLE_DOT
MARKERTYPE_ASTERISK
MARKERTYPE_BOWTIE
MARKERTYPE_CIRCLE
MARKERTYPE_DIAGONAL_CROSS
MARKERTYPE_DIAMOND
MARKERTYPE_DOT
MARKERTYPE_HEPTAGON
MARKERTYPE_HEXAGON
MARKERTYPE_HLINE
MARKERTYPE_HOLLOW_PLUS
MARKERTYPE_HOURGLASS
MARKERTYPE_OCTAGON
MARKERTYPE_OMARK
MARKERTYPE_PENTAGON
MARKERTYPE_PLUS
MARKERTYPE_SOLID_BOWTIE
MARKERTYPE_SOLID_CIRCLE
MARKERTYPE_SOLID_DIAMOND
MARKERTYPE_SOLID_HGLASS
MARKERTYPE_SOLID_PLUS
MARKERTYPE_SOLID_SQUARE
MARKERTYPE_SOLID_STAR
MARKERTYPE_SOLID_TRI_DOWN
MARKERTYPE_SOLID_TRI_LEFT
MARKERTYPE_SOLID_TRI_RIGHT
MARKERTYPE_SOLID_TRI_UP
MARKERTYPE_SQUARE
MARKERTYPE_STAR
MARKERTYPE_STAR_4
MARKERTYPE_STAR_5
MARKERTYPE_STAR_6
MARKERTYPE_STAR_7
MARKERTYPE_STAR_8
MARKERTYPE_TRIANGLE_DOWN
MARKERTYPE_TRIANGLE_UP
MARKERTYPE_TRI_UP_DOWN
MARKERTYPE_VLINE
MODEL_HSV
MODEL_RGB
MPL_POSTPONE_UPDATE
MPL_SUPPRESS_CLEAR
NOCLIP
OPTION_CELL_ARRAY
OPTION_COLORED_MESH
OPTION_FILLED_MESH
OPTION_FLIP_X
OPTION_FLIP_Y
OPTION_FLIP_Z
OPTION_LINES
OPTION_MESH
OPTION_SHADED_MESH
OPTION_X_LOG
OPTION_Y_LOG
OPTION_Z_LOG
OPTION_Z_SHADED_MESH
PATH_CLOSEPOLY
PATH_CURVE3
PATH_CURVE4
PATH_LINETO
PATH_MOVETO
PATH_STOP

GR.beginprint types

PROJECTION_DEFAULT
PROJECTION_ORTHOGRAPHIC
PROJECTION_PERSPECTIVE
RESAMPLE_DEFAULT
RESAMPLE_LANCZOS
RESAMPLE_LINEAR
RESAMPLE_NEAREST
TEXT_HALIGN_CENTER
TEXT_HALIGN_LEFT
TEXT_HALIGN_NORMAL
TEXT_HALIGN_RIGHT
TEXT_PATH_DOWN
TEXT_PATH_LEFT
TEXT_PATH_RIGHT
TEXT_PATH_UP
TEXT_PRECISION_CHAR
TEXT_PRECISION_STRING
TEXT_PRECISION_STROKE
TEXT_VALIGN_BASE
TEXT_VALIGN_BOTTOM
TEXT_VALIGN_CAP
TEXT_VALIGN_HALF
TEXT_VALIGN_NORMAL
TEXT_VALIGN_TOP
UPSAMPLE_HORIZONTAL_DEFAULT
UPSAMPLE_HORIZONTAL_LANCZOS
UPSAMPLE_HORIZONTAL_LINEAR
UPSAMPLE_HORIZONTAL_NEAREST
UPSAMPLE_VERTICAL_DEFAULT
UPSAMPLE_VERTICAL_LANCZOS
UPSAMPLE_VERTICAL_LINEAR
UPSAMPLE_VERTICAL_NEAREST
VERSION
XFORM_BOOLEAN
XFORM_CUBIC
XFORM_EQUALIZED
XFORM_LINEAR
XFORM_LOG
XFORM_LOGLOG

Attributes

ffi_lib[RW]

Public Class Methods

_contour_(x, y, h, z, major_h)
Alias for: contour
_contourf_(x, y, h, z, major_h)
Alias for: contourf
_hexbin_(x, y, nbins)
Alias for: hexbin
_shade_(*args)
Alias for: shade
_surface_(x, y, z, option)

(Plot) Draw a three-dimensional surface plot.

Alias for: surface
adjustlimits(amin, amax) click to toggle source

@return [Integer] @!method validaterange

Calls superclass method
# File lib/gr.rb, line 1475
def adjustlimits(amin, amax)
  inquiry %i[double double] do |pamin, pamax|
    pamin.write_double amin
    pamax.write_double amax
    super(pamin, pamax)
  end
end
adjustrange(amin, amax) click to toggle source
Calls superclass method
# File lib/gr.rb, line 1483
def adjustrange(amin, amax)
  inquiry %i[double double] do |pamin, pamax|
    pamin.write_double amin
    pamax.write_double amax
    super(pamin, pamax)
  end
end
barplot(labels, heights, kv = {}) click to toggle source

(Plot) Draw a bar plot.

# File lib/gr/plot.rb, line 1402
def barplot(labels, heights, kv = {})
  labels = labels.map(&:to_s)
  wc, hc = barcoordinates(heights)
  create_plot(:bar, labels, heights, kv) do |plt|
    if kv[:horizontal]
      plt.args = [[hc, wc, nil, nil, '']]
      plt.kvs[:yticks] = [1, 1]
      plt.kvs[:yticklabels] = labels
    else
      plt.args = [[wc, hc, nil, nil, '']]
      plt.kvs[:xticks] = [1, 1]
      plt.kvs[:xticklabels] = labels
    end
  end
end
beginprint(file_path) { || ... } click to toggle source

Open and activate a print device.

`beginprint` opens an additional graphics output device. The device type is obtained from the given file extension

@param pathname [String] Filename for the print device.

The following file types are supported:
* .ps, .eps   : PostScript
* .pdf        : Portable Document Format
* .bmp        : Windows Bitmap (BMP)
* .jpeg, .jpg : JPEG image file
* .png        : Portable Network Graphics file (PNG)
* .tiff, .tif : Tagged Image File Format (TIFF)
* .svg        : Scalable Vector Graphics
* .wmf        : Windows Metafile
* .mp4        : MPEG-4 video file
* .webm       : WebM video file
* .ogg        : Ogg video file

@note Ruby feature - you can use block to call endprint automatically.

Calls superclass method
# File lib/gr.rb, line 1512
def beginprint(file_path)
  super(file_path)
  if block_given?
    yield
    endprint
  end
end
cellarray(xmin, xmax, ymin, ymax, dimx, dimy, color) click to toggle source

Display rasterlike images in a device-independent manner. The cell array function partitions a rectangle given by two corner points into DIMX X DIMY cells, each of them colored individually by the corresponding color index of the given cell array.

@param xmin [Numeric] Lower left point of the rectangle @param ymin [Numeric] Lower left point of the rectangle @param xmax [Numeric] Upper right point of the rectangle @param ymax [Numeric] Upper right point of the rectangle @param dimx [Integer] X dimension of the color index array @param dimy [Integer] Y dimension of the color index array @param color [Array, NArray] Color index array

The values for `xmin`, `xmax`, `ymin` and `ymax` are in world coordinates.

Calls superclass method
# File lib/gr.rb, line 304
def cellarray(xmin, xmax, ymin, ymax, dimx, dimy, color)
  super(xmin, xmax, ymin, ymax, dimx, dimy, 1, 1, dimx, dimy, int(color))
end
contour(x, y, h, z, major_h) click to toggle source

Draw contours of a three-dimensional data set whose values are specified over a rectangular mesh. Contour lines may optionally be labeled.

@note `contour` is overwritten by `require gr/plot`.

The original method is moved to the underscored name.
The yard document will show the method name after evacuation.

@param x [Array, NArray] A list containing the X coordinates @param y [Array, NArray] A list containing the Y coordinates @param h [Array, NArray]

A list containing the Z coordinate for the height values

@param z [Array, NArray]

A list containing the Z coordinate for the height values
A list of length `len(x)` * `len(y)` or an appropriately dimensioned
array containing the Z coordinates

@param major_h [Integer]

Directs GR to label contour lines. For example, a value of 3 would label
every third line. A value of 1 will label every line. A value of 0
produces no labels. To produce colored contour lines, add an offset
of 1000 to `major_h`.
Calls superclass method
# File lib/gr.rb, line 1345
def contour(x, y, h, z, major_h)
  # TODO: check: Arrays have incorrect length or dimension.
  nx = x.length
  ny = y.length
  nh = h.length
  super(nx, ny, nh, x, y, h, z, major_h)
end
Also aliased as: _contour_
contourf(x, y, h, z, major_h) click to toggle source

Draw filled contours of a three-dimensional data set whose values are specified over a rectangular mesh.

@note `contourf` is overwritten by `require gr/plot`.

The original method is moved to the underscored name.
The yard document will show the method name after evacuation.

@param x [Array, NArray] A list containing the X coordinates @param y [Array, NArray] A list containing the Y coordinates @param h [Array, NArray]

A list containing the Z coordinate for the height values or the number
of contour lines which will be evenly distributed between minimum and
maximum Z value

@param z [Array, NArray]

A list of length `len(x)` * `len(y)` or an appropriately dimensioned
array containing the Z coordinates
Calls superclass method
# File lib/gr.rb, line 1370
def contourf(x, y, h, z, major_h)
  # TODO: check: Arrays have incorrect length or dimension.
  nx = x.length
  ny = y.length
  nh = h.length
  super(nx, ny, nh, x, y, h, z, major_h)
end
Also aliased as: _contourf_
delaunay(x, y) click to toggle source

@return [Integer] @!method uselinespec

Calls superclass method
# File lib/gr.rb, line 1840
def delaunay(x, y)
  # Feel free to make a pull request if you catch a mistake
  # or you have an idea to improve it.
  npoints = equal_length(x, y)
  triangles = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INTPTR_T)
  dim = 3
  n_tri = inquiry_int do |ntri|
    super(npoints, x, y, ntri, triangles.ref)
  end
  if n_tri > 0
    tri = triangles.to_str(dim * n_tri * Fiddle::SIZEOF_INT).unpack('l*') # Int32
    # Ruby  : 0-based indexing
    # Julia : 1-based indexing
    tri = tri.each_slice(dim).to_a
    [n_tri, tri]
  else
    0
  end
end
drawimage(xmin, xmax, ymin, ymax, width, height, data, model = 0) click to toggle source

Draw an image into a given rectangular area.

The points (`xmin`, `ymin`) and (`xmax`, `ymax`) are world coordinates defining diagonally opposite corner points of a rectangle. This rectangle is divided into `width` by `height` cells. The two-dimensional array `data` specifies colors for each cell.

@param xmin [Numeric] First corner point of the rectangle @param ymin [Numeric] First corner point of the rectangle @param xmax [Numeric] Second corner point of the rectangle @param ymax [Numeric] Second corner point of the rectangle @param width [Integer] The width and the height of the image @param height [Integer] The width and the height of the image @param data [Array, NArray] An array of color values dimensioned `width` by `height` @param model [Integer] Color model ( default = 0 )

The available color models are:
* 0 : MODEL_RGB - AABBGGRR
* 1 : MODEL_HSV - AAVVSSHH
Calls superclass method
# File lib/gr.rb, line 1734
def drawimage(xmin, xmax, ymin, ymax, width, height, data, model = 0)
  super(xmin, xmax, ymin, ymax, width, height, uint(data), model)
end
drawpath(points, codes, fill) click to toggle source

Draw simple and compound outlines consisting of line segments and bezier curves.

@param points [Array, NArray] (N, 2) array of (x, y) vertices @param codes [Array, NArray] N-length array of path codes

*  STOP      : end the entire path
*  MOVETO    : move to the given vertex
*  LINETO    : draw a line from the current position to the given vertex
*  CURVE3    : draw a quadratic Bézier curve
*  CURVE4    : draw a cubic Bézier curve
*  CLOSEPOLY : draw a line segment to the start point of the current path

@param fill [Integer]

A flag indication whether resulting path is to be filled or not
Calls superclass method
# File lib/gr.rb, line 1649
def drawpath(points, codes, fill)
  len = codes.length
  super(len, points, uint8(codes), fill)
end
fillarea(x, y) click to toggle source

Allows you to specify a polygonal shape of an area to be filled.

@param x [Array, NArray] A list containing the X coordinates @param y [Array, NArray] A list containing the Y coordinates

The attributes that control the appearance of fill areas are fill area interior style, fill area style index and fill area color index.

Calls superclass method
# File lib/gr.rb, line 284
def fillarea(x, y)
  n = equal_length(x, y)
  super(n, x, y)
end
gdp(x, y, primid, datrec) click to toggle source

Generates a generalized drawing primitive (GDP) of the type you specify, using specified points and any additional information contained in a data record.

@param x [Array, NArray] A list containing the X coordinates @param y [Array, NArray] A list containing the Y coordinates @param primid [Integer] Primitive identifier @param datrec [Array, NArray] Primitive data record

Calls superclass method
# File lib/gr.rb, line 404
def gdp(x, y, primid, datrec)
  n = equal_length(x, y)
  ldr = datrec.length
  super(n, x, y, primid, ldr, int(datrec))
end
getgraphics(*) click to toggle source

@return [String]

Calls superclass method
# File lib/gr.rb, line 1784
def getgraphics(*)
  super.to_s
end
gradient(x, y, z) click to toggle source

@deprecated

Calls superclass method
# File lib/gr.rb, line 1886
def gradient(x, y, z)
  # TODO: check: Arrays have incorrect length or dimension.
  nx = x.length
  ny = y.length
  inquiry [{ double: nx * ny }, { double: nx * ny }] do |pu, pv|
    super(nx, ny, x, y, z, pu, pv)
  end
end
gridit(xd, yd, zd, nx, ny) click to toggle source

Interpolate data from arbitrary points at points on a rectangular grid.

@param xd [Array, NArray] X coordinates of the input points @param yd [Array, NArray] Y coordinates of the input points @param zd [Array, NArray] values of the points @param nx [Array, NArray] The number of points in X direction for the

output grid

@param ny [Array, NArray] The number of points in Y direction for the

output grid
Calls superclass method
# File lib/gr.rb, line 441
def gridit(xd, yd, zd, nx, ny)
  nd = equal_length(xd, yd, zd)
  inquiry [{ double: nx }, { double: ny }, { double: nx * ny }] do |px, py, pz|
    super(nd, xd, yd, zd, nx, ny, px, py, pz)
  end
end
heatmap(*args) click to toggle source

(Plot) Draw a heatmap.

# File lib/gr/plot.rb, line 1292
def heatmap(*args)
  # FIXME
  args, kv = format_xyzc(*args)
  _x, _y, z = args
  ysize, xsize = z.shape
  z = z.reshape(xsize, ysize)
  create_plot(:heatmap, kv) do |plt|
    plt.kvs[:xlim] ||= [0.5, xsize + 0.5]
    plt.kvs[:ylim] ||= [0.5, ysize + 0.5]
    plt.args = [[(1..xsize).to_a, (1..ysize).to_a, z, nil, '']]
  end
end
herrorbars(x, y, e1, e2) click to toggle source

Draw a standard horizontal error bar graph.

@param x [Array, NArray] A list of length N containing the X coordinates @param y [Array, NArray] A list of length N containing the Y coordinates @param e1 [Array, NArray] The absolute values of the lower error bar data @param e2 [Array, NArray] The absolute values of the lower error bar data

Calls superclass method
# File lib/gr.rb, line 1209
def herrorbars(x, y, e1, e2)
  n = equal_length(x, y, e1, e2)
  super(n, x, y, e1, e2)
end
hexbin(x, y, nbins) click to toggle source

@note `hexbin` is overwritten by `require gr/plot`.

The original method is moved to the underscored name.
The yard document will show the method name after evacuation.

@return [Integer]

Calls superclass method
# File lib/gr.rb, line 1396
def hexbin(x, y, nbins)
  n = x.length
  super(n, x, y, nbins)
end
Also aliased as: _hexbin_
histogram(series, kv = {}) click to toggle source

(Plot) Draw a histogram.

# File lib/gr/plot.rb, line 1419
def histogram(series, kv = {})
  create_plot(:hist, series, kv) do |plt|
    nbins = plt.kvs[:nbins] || 0
    x, y = hist(series, nbins)
    plt.args = if kv[:horizontal]
                 [[y, x, nil, nil, '']]
               else
                 [[x, y, nil, nil, '']]
               end
  end
end
hold(flag = true) click to toggle source
# File lib/gr/plot.rb, line 1447
def hold(flag = true)
  plt = GR::Plot.last_plot
  plt.kvs.slice(:window, :scale, :xaxis, :yaxis, :zaxis).merge({ ax: flag, clear: !flag })
end
hsvtorgb(h, s, v) click to toggle source

@return [Integer] @!method inqcolorfromrgb

Calls superclass method
# File lib/gr.rb, line 1463
def hsvtorgb(h, s, v)
  inquiry %i[double double double] do |r, g, b|
    super(h, s, v, r, g, b)
  end
end
imshow(img, kv = {}) click to toggle source

(Plot) Draw an image.

# File lib/gr/plot.rb, line 1432
def imshow(img, kv = {})
  img = Numo::DFloat.cast(img) # Umm...
  create_plot(:imshow, img, kv) do |plt|
    plt.args = [[nil, nil, img, nil, '']]
  end
end
inqbbox() click to toggle source

@!method resizeselection

Calls superclass method
# File lib/gr.rb, line 1815
def inqbbox
  inquiry %i[double double double double] do |*pts|
    super(*pts)
  end
end
inqbordercolorind() click to toggle source

Define the color of subsequent path output primitives.

@param color [Integer] The border color index (COLOR < 1256)

@!method setbordercolorind

Calls superclass method
# File lib/gr.rb, line 2137
def inqbordercolorind
  inquiry_int { |pt| super(pt) }
end
inqborderwidth() click to toggle source

Define the border width of subsequent path output primitives.

@param width [Numeric] The border width scale factor

@!method setborderwidth

Calls superclass method
# File lib/gr.rb, line 2127
def inqborderwidth
  inquiry_double { |pt| super(pt) }
end
inqcharheight() click to toggle source

Gets the current character height.

This function gets the height of text output primitives. Text height is defined as a percentage of the default window. GR uses the default text height of 0.027 (2.7% of the height of the default window).

@return [Numeric] Text height value

Calls superclass method
# File lib/gr.rb, line 673
def inqcharheight
  inquiry_double { |pt| super(pt) }
end
inqclipxform() click to toggle source

@!method selectclipxform

Calls superclass method
# File lib/gr.rb, line 2143
def inqclipxform
  inquiry_int { |pt| super(pt) }
end
inqcolor(color) click to toggle source

@!method colorbar

Calls superclass method
# File lib/gr.rb, line 1454
def inqcolor(color)
  inquiry_int do |rgb|
    super(color, rgb)
  end
end
inqcolormap() click to toggle source

inqcolormap

Calls superclass method
# File lib/gr.rb, line 1411
def inqcolormap
  inquiry_int { |pt| super(pt) }
end
inqcolormapinds() click to toggle source

Inquire the color index range of the current colormap.

@return [Array] first_color_ind The color index of the first color,

last_color_ind The color index of the last color
Calls superclass method
# File lib/gr.rb, line 1446
def inqcolormapinds
  inquiry %i[int int] do |first_color_ind, last_color_ind|
    super(first_color_ind, last_color_ind)
  end
end
inqdspsize() click to toggle source

Get the current display size.

Depending on the current workstation type, the current display might be the primary screen (e.g. when using gksqt or GKSTerm) or a purely virtual display (e.g. when using Cairo). When a high DPI screen is used as the current display, width and height will be in logical pixels.

@return [Array] meter_width, meter_height, width, height

Calls superclass method
# File lib/gr.rb, line 112
def inqdspsize
  inquiry %i[double double int int] do |*pts|
    super(*pts)
  end
end
inqfillcolorind() click to toggle source

Returns the current fill area color index.

This function gets the color of fill area output primitives.

@return [Integer] The text color index (COLOR < 1256)

Calls superclass method
# File lib/gr.rb, line 781
def inqfillcolorind
  inquiry_int { |pt| super(pt) }
end
inqfillintstyle() click to toggle source

Returns the fill area interior style to be used for fill areas.

This function gets the currently set fill style.

@return [Integer] The currently set fill style

Calls superclass method
# File lib/gr.rb, line 740
def inqfillintstyle
  inquiry_int { |pt| super(pt) }
end
inqfillstyle() click to toggle source

Returns the current fill area color index.

This function gets the color index for PATTERN and HATCH fills.

@return [Integer] The currently set fill style color index

Calls superclass method
# File lib/gr.rb, line 762
def inqfillstyle
  inquiry_int { |pt| super(pt) }
end
inqlinecolorind() click to toggle source

Define the color of subsequent polyline output primitives.

@param color [Integer] The polyline color index (COLOR < 1256)

@!method setlinecolorind

Calls superclass method
# File lib/gr.rb, line 491
def inqlinecolorind
  inquiry_int { |pt| super(pt) }
end
inqlinetype() click to toggle source

Specify the line style for polylines.

@param style [Integer] The polyline line style

* 1  : LINETYPE_SOLID           - Solid line
* 2  : LINETYPE_DASHED          - Dashed line
* 3  : LINETYPE_DOTTED          - Dotted line
* 4  : LINETYPE_DASHED_DOTTED   - Dashed-dotted line
* -1 : LINETYPE_DASH_2_DOT      - Sequence of one dash followed by two dots
* -2 : LINETYPE_DASH_3_DOT      - Sequence of one dash followed by three dots
* -3 : LINETYPE_LONG_DASH       - Sequence of long dashes
* -4 : LINETYPE_LONG_SHORT_DASH - Sequence of a long dash followed by a short dash
* -5 : LINETYPE_SPACED_DASH     - Sequence of dashes double spaced
* -6 : LINETYPE_SPACED_DOT      - Sequence of dots double spaced
* -7 : LINETYPE_DOUBLE_DOT      - Sequence of pairs of dots
* -8 : LINETYPE_TRIPLE_DOT      - Sequence of groups of three dots

@!method setlinetype

Calls superclass method
# File lib/gr.rb, line 466
def inqlinetype
  inquiry_int { |pt| super(pt) }
end
inqlinewidth() click to toggle source

Define the line width of subsequent polyline output primitives.

The line width is calculated as the nominal line width generated on the workstation multiplied by the line width scale factor. This value is mapped by the workstation to the nearest available line width. The default line width is 1.0, or 1 times the line width generated on the graphics device.

@param width [Numeric] The polyline line width scale factor

@!method setlinewidth

Calls superclass method
# File lib/gr.rb, line 481
def inqlinewidth
  inquiry_double { |pt| super(pt) }
end
inqmarkercolorind() click to toggle source

Define the color of subsequent polymarker output primitives.

@param color [Integer] The polymarker color index (COLOR < 1256)

@!method setmarkercolorind

Calls superclass method
# File lib/gr.rb, line 567
def inqmarkercolorind
  inquiry_int { |pt| super(pt) }
end
inqmarkersize() click to toggle source

Inquire the marker size for polymarkers.

@return [Numeric] Scale factor applied to the nominal marker size

Calls superclass method
# File lib/gr.rb, line 557
def inqmarkersize
  inquiry_double { |pt| super(pt) }
end
inqmarkertype() click to toggle source

Specifiy the marker type for polymarkers.

@param style [Integer] The polymarker marker type

* 1   : MARKERTYPE_DOT             - Smallest displayable dot
* 2   : MARKERTYPE_PLUS            - Plus sign
* 3   : MARKERTYPE_ASTERISK        - Asterisk
* 4   : MARKERTYPE_CIRCLE          - Hollow circle
* 5   : MARKERTYPE_DIAGONAL_CROSS  - Diagonal cross
* -1  : MARKERTYPE_SOLID_CIRCLE    - Filled circle
* -2  : MARKERTYPE_TRIANGLE_UP     - Hollow triangle pointing upward
* -3  : MARKERTYPE_SOLID_TRI_UP    - Filled triangle pointing upward
* -4  : MARKERTYPE_TRIANGLE_DOWN   - Hollow triangle pointing downward
* -5  : MARKERTYPE_SOLID_TRI_DOWN  - Filled triangle pointing downward
* -6  : MARKERTYPE_SQUARE          - Hollow square
* -7  : MARKERTYPE_SOLID_SQUARE    - Filled square
* -8  : MARKERTYPE_BOWTIE          - Hollow bowtie
* -9  : MARKERTYPE_SOLID_BOWTIE    - Filled bowtie
* -10 : MARKERTYPE_HGLASS          - Hollow hourglass
* -11 : MARKERTYPE_SOLID_HGLASS    - Filled hourglass
* -12 : MARKERTYPE_DIAMOND         - Hollow diamond
* -13 : MARKERTYPE_SOLID_DIAMOND   - Filled Diamond
* -14 : MARKERTYPE_STAR            - Hollow star
* -15 : MARKERTYPE_SOLID_STAR      - Filled Star
* -16 : MARKERTYPE_TRI_UP_DOWN     - Hollow triangles pointing up and down overlaid
* -17 : MARKERTYPE_SOLID_TRI_RIGHT - Filled triangle point right
* -18 : MARKERTYPE_SOLID_TRI_LEFT  - Filled triangle pointing left
* -19 : MARKERTYPE_HOLLOW PLUS     -  Hollow plus sign
* -20 : MARKERTYPE_SOLID PLUS      - Solid plus sign
* -21 : MARKERTYPE_PENTAGON        - Pentagon
* -22 : MARKERTYPE_HEXAGON         - Hexagon
* -23 : MARKERTYPE_HEPTAGON        - Heptagon
* -24 : MARKERTYPE_OCTAGON         - Octagon
* -25 : MARKERTYPE_STAR_4          - 4-pointed star
* -26 : MARKERTYPE_STAR_5          - 5-pointed star (pentagram)
* -27 : MARKERTYPE_STAR_6          - 6-pointed star (hexagram)
* -28 : MARKERTYPE_STAR_7          - 7-pointed star (heptagram)
* -29 : MARKERTYPE_STAR_8          - 8-pointed star (octagram)
* -30 : MARKERTYPE_VLINE           - verical line
* -31 : MARKERTYPE_HLINE           - horizontal line
* -32 : MARKERTYPE_OMARK           - o-mark

Polymarkers appear centered over their specified coordinates.

@!method setmarkertype

Calls superclass method
# File lib/gr.rb, line 540
def inqmarkertype
  inquiry_int { |pt| super(pt) }
end
inqmathtex(x, y, string) click to toggle source

inqmathtex

Calls superclass method
# File lib/gr.rb, line 1801
def inqmathtex(x, y, string)
  inquiry [{ double: 4 }, { double: 4 }] do |tbx, tby|
    super(x, y, string, tbx, tby)
  end
end
inqorthographicprojection() click to toggle source

Return the camera position, up vector and focus point.

Calls superclass method
# File lib/gr.rb, line 2217
def inqorthographicprojection
  inquiry([:double] * 6) do |*pts|
    super(*pts)
  end
end
inqperspectiveprojection() click to toggle source

Return the parameters for the perspective projection.

Calls superclass method
# File lib/gr.rb, line 2174
def inqperspectiveprojection
  inquiry %i[double double double] do |*pts|
    super(*pts)
  end
end
inqprojectiontype() click to toggle source

Return the projection type.

Calls superclass method
# File lib/gr.rb, line 2158
def inqprojectiontype
  inquiry_int { |pt| super(pt) }
end
inqresamplemethod() click to toggle source

Inquire the resample method used for `drawimage`

@return [Integer] Resample flag

Calls superclass method
# File lib/gr.rb, line 2069
def inqresamplemethod
  inquiry_uint do |resample_method|
    super(resample_method)
  end
end
inqscale() click to toggle source

inqscale

Calls superclass method
# File lib/gr.rb, line 981
def inqscale
  inquiry_int { |pt| super(pt) }
end
inqscalefactors3d() click to toggle source

Returns the scale factors for each axis.

Calls superclass method
# File lib/gr.rb, line 2265
def inqscalefactors3d
  inquiry %i[double double double] do |*opts|
    super(*opts)
  end
end
inqspace() click to toggle source

Set the abstract Z-space used for mapping three-dimensional output primitives into the current world coordinate space.

`setspace` establishes the limits of an abstract Z-axis and defines the angles for rotation and for the viewing angle (tilt) of a simulated three-dimensional graph, used for mapping corresponding output primitives into the current window. These settings are used for all subsequent three-dimensional output primitives until other values are specified. Angles of rotation and viewing angle must be specified between 0° and 90°.

@param zmin [Numeric] Minimum value for the Z-axis. @param zmax [Numeric] Maximum value for the Z-axis. @param rotation [Integer] Angle for the rotation of the X axis, in degrees. @param tilt [integer] Viewing angle of the Z axis in degrees.

@return [Integer]

@!method setspace

Calls superclass method
# File lib/gr.rb, line 949
def inqspace
  inquiry %i[double double int int] do |*pts|
    super(*pts)
  end
end
inqtext(x, y, string) click to toggle source

Draw a text at position `x`, `y` using the current text attributes.

@param x [Numeric] The X coordinate of starting position of the text

string

@param y [Numeric] The Y coordinate of starting position of the text

string

@param string [String] The text to be drawn

The values for `x` and `y` are in normalized device coordinates. The attributes that control the appearance of text are text font and precision, character expansion factor, character spacing, text color index, character height, character up vector, text path and text alignment.

@!method text

Calls superclass method
# File lib/gr.rb, line 270
def inqtext(x, y, string)
  inquiry [{ double: 4 }, { double: 4 }] do |tbx, tby|
    super(x, y, string, tbx, tby)
  end
end
inqtext3d(x, y, z, string, axis) click to toggle source

@!method text3d

Calls superclass method
# File lib/gr.rb, line 2290
def inqtext3d(x, y, z, string, axis)
  inquiry [{ double: 16 }, { double: 16 }] do |tbx, tby|
    super(x, y, z, string, axis, tbx, tby)
  end
end
inqtextcolorind() click to toggle source

Gets the current text color index.

This function gets the color of text output primitives.

@return [Integer] color The text color index (COLOR < 1256)

Calls superclass method
# File lib/gr.rb, line 652
def inqtextcolorind
  inquiry_int { |pt| super(pt) }
end
inqtextencoding() click to toggle source

@!method settextencoding

Calls superclass method
# File lib/gr.rb, line 2298
def inqtextencoding
  inquiry_int do |encoding|
    super(encoding)
  end
end
inqtextext(x, y, string) click to toggle source

inqtextext

Calls superclass method
# File lib/gr.rb, line 1043
def inqtextext(x, y, string)
  inquiry [{ double: 4 }, { double: 4 }] do |tbx, tby|
    super(x, y, string, tbx, tby)
  end
end
inqtransformationparameters() click to toggle source

Return the camera position, up vector and focus point.

Calls superclass method
# File lib/gr.rb, line 2197
def inqtransformationparameters
  inquiry([:double] * 9) do |*pts|
    super(*pts)
  end
end
inqviewport() click to toggle source

inqviewport

Calls superclass method
# File lib/gr.rb, line 845
def inqviewport
  inquiry %i[double double double double] do |*pts|
    super(*pts)
  end
end
inqwindow() click to toggle source

inqwindow

Calls superclass method
# File lib/gr.rb, line 818
def inqwindow
  inquiry %i[double double double double] do |*pts|
    super(*pts)
  end
end
inqwindow3d() click to toggle source

Return the three dimensional window.

Calls superclass method
# File lib/gr.rb, line 2248
def inqwindow3d
  inquiry([:double] * 6) do |*pts|
    super(*pts)
  end
end
interp2(x, y, z, xq, yq, method, extrapval) click to toggle source

Interpolation in two dimensions using one of four different methods. The input points are located on a grid, described by `x`, `y` and `z`. The target grid ist described by `xq` and `yq`. Returns an array containing the resulting z-values.

@param x [Array, NArray] Array containing the input grid's x-values @param y [Array, NArray] Array containing the input grid's y-values @param z [Array, NArray] Array containing the input grid's z-values (number of values: nx * ny) @param xq [Array, NArray] Array containing the target grid's x-values @param yq [Array, NArray] Array containing the target grid's y-values @param method [Integer] Used method for interpolation

The available methods for interpolation are the following:
* 0 : INTERP2_NEAREST - Nearest neighbour interpolation
* 1 : INTERP2_LINEAR  - Linear interpolation
* 2 : INTERP_2_SPLINE - Interpolation using natural cubic splines
* 3 : INTERP2_CUBIC   - Cubic interpolation

@param extrapval [Numeric] The extrapolation value

flatten

Calls superclass method
# File lib/gr.rb, line 1935
def interp2(x, y, z, xq, yq, method, extrapval)
  nx = x.length
  ny = y.length
  # nz = z.length
  nxq = xq.length
  nyq = yq.length
  inquiry(double: nxq * nyq) do |zq|
    super(nx, ny, x, y, z, nxq, nyq, xq, yq, zq, method, extrapval)
  end
end
isosurface(v, kv = {}) click to toggle source

(Plot) Draw an isosurface.

# File lib/gr/plot.rb, line 1440
def isosurface(v, kv = {})
  v = Numo::DFloat.cast(v) # Umm...
  create_plot(:isosurface, v, kv) do |plt|
    plt.args = [[nil, nil, v, nil, '']]
  end
end
loadfont(str) click to toggle source

Load a font file from a given filename.

This function loads a font from a given absolute filename and assigns a font index to it. To use the loaded font call `gr_settextfontprec` using the resulting font index and precision 3.

@param filename [String] The absolute filename of the font

Calls superclass method
# File lib/gr.rb, line 2312
def loadfont(str)
  inquiry_int do |font|
    super(str, font)
  end
end
ndctowc(x, y) click to toggle source

@!method endprint

Calls superclass method
# File lib/gr.rb, line 1562
def ndctowc(x, y)
  inquiry %i[double double] do |px, py|
    px.write_double x
    py.write_double y
    super(px, py)
  end
end
nonuniformcellarray(x, y, dimx, dimy, color) click to toggle source

Display a two dimensional color index array with nonuniform cell sizes.

@param x [Array, NArray] X coordinates of the cell edges @param y [Array, NArray] Y coordinates of the cell edges @param dimx [Integer] X dimension of the color index array @param dimy [Integer] Y dimension of the color index array @param color [Array, NArray] Color index array

The values for `x` and `y` are in world coordinates. `x` must contain `dimx` + 1 elements and `y` must contain `dimy` + 1 elements. The elements i and i+1 are respectively the edges of the i-th cell in X and Y direction.

Calls superclass method
# File lib/gr.rb, line 320
def nonuniformcellarray(x, y, dimx, dimy, color)
  raise ArgumentError unless x.length == dimx + 1 && y.length == dimy + 1

  nx = dimx == x.length ? -dimx : dimx
  ny = dimy == y.length ? -dimy : dimy
  super(x, y, nx, ny, 1, 1, dimx, dimy, int(color))
end
nonuniformpolarcellarray(phi, r, ncol, nrow, color) click to toggle source

Display a two dimensional color index array mapped to a disk using polar coordinates with nonuniform cell sizes.

@param phi [Array, NArray] array with the angles of the disk sector in degrees @param r [Array, NArray] array with the radii of the disk in world coordinates @param ncol [Integer] total number of columns in the color index array and the angle array @param nrow [Integer] total number of rows in the color index array and the radii array @param color [Integer] color index array

The mapping of the polar coordinates and the drawing is performed simialr to `gr_polarcellarray` with the difference that the individual cell sizes are specified allowing nonuniform sized cells.

Calls superclass method
# File lib/gr.rb, line 387
def nonuniformpolarcellarray(phi, r, ncol, nrow, color)
  raise ArgumentError unless (ncol..(ncol + 1)).include?(phi.length) && (nrow..(nrow + 1)).include?(r.length)

  dimphi = ncol == phi.length ? -ncol : ncol
  dimr = nrow == r.length ? -nrow : nrow
  super(0, 0, phi, r, dimphi, dimr, 1, 1, ncol, nrow, int(color))
end
nonuniformpolarheatmap(*args) click to toggle source

(Plot) Draw a nonuniformpolarheatmap.

# File lib/gr/plot.rb, line 1321
def nonuniformpolarheatmap(*args)
  # FIXME
  args, kv = format_xyzc(*args)
  _x, _y, z = args
  ysize, xsize = z.shape
  z = z.reshape(xsize, ysize)
  create_plot(:nonuniformpolarheatmap, kv) do |plt|
    plt.kvs[:xlim] ||= [0.5, xsize + 0.5]
    plt.kvs[:ylim] ||= [0.5, ysize + 0.5]
    plt.args = [[(1..xsize).to_a, (1..ysize).to_a, z, nil, '']]
  end
end
panzoom(x, y, zoom) click to toggle source

panzoom

Calls superclass method
# File lib/gr.rb, line 2011
def panzoom(x, y, zoom)
  inquiry %i[double double double double] do |xmin, xmax, ymin, ymax|
    super(x, y, zoom, zoom, xmin, xmax, ymin, ymax)
  end
end
path(x, y, codes) click to toggle source

Draw paths using the given vertices and path codes.

@param x [Array, NArray] A list containing the X coordinates @param y [Array, NArray] A list containing the Y coordinates @param codes [String] A list containing the path codes

The following path codes are recognized:
* M, m
  * moveto                      x, y
* L, l
  * lineto                      x, y
* Q, q
  * quadratic Bézier            x1, x2  y1, y2
* C, c
  * cubic Bézier                x1, x2, x3  y1, y2, y3
* A, a
  * arc                         rx, a1, reserved  ry, a2, reserved
* Z
  * close path                  -
* s
  * stroke                      -
* s
  * close path and stroke       -
* f
  * close path and fill         -
* F
  * close path, fill and stroke -

See gr-framework.org/python-gr.html#gr.path for more details.

Calls superclass method
# File lib/gr.rb, line 2104
def path(x, y, codes)
  n = equal_length(x, y)
  super(n, x, y, codes)
end
plot(*args) click to toggle source

(Plot) Draw one or more line plots.

# File lib/gr/plot.rb, line 1262
def plot(*args)
  create_plot(:line, *args)
end
plot3(*args) click to toggle source

(Plot) Draw one or more three-dimensional line plots.

# File lib/gr/plot.rb, line 1379
def plot3(*args)
  create_plot(:plot3, *args)
end
polar(*args) click to toggle source

(Plot)

# File lib/gr/plot.rb, line 1369
def polar(*args)
  create_plot(:polar, *args)
end
polarcellarray(x_org, y_org, phimin, phimax, rmin, rmax, dimphi, dimr, color) click to toggle source

Display a two dimensional color index array mapped to a disk using polar coordinates.

The two dimensional color index array is mapped to the resulting image by interpreting the X-axis of the array as the angle and the Y-axis as the raidus. The center point of the resulting disk is located at `xorg`, `yorg` and the radius of the disk is `rmax`.

@param x_org [Numeric] X coordinate of the disk center in world

coordinates

@param y_org [Numeric] Y coordinate of the disk center in world

coordinates

@param phimin [Numeric] start angle of the disk sector in degrees @param phimax [Numeric] end angle of the disk sector in degrees @param rmin [Numeric] inner radius of the punctured disk in world

coordinates

@param rmax [Numeric] outer radius of the punctured disk in world

coordinates

@param dimphi [Integer] Phi (X) dimension of the color index array @param dimr [Integer] iR (Y) dimension of the color index array @param color [Array, NArray] Color index array

The additional parameters to the function can be used to further control the mapping from polar to cartesian coordinates.

If `rmin` is greater than 0 the input data is mapped to a punctured disk (or annulus) with an inner radius of `rmin` and an outer radius `rmax`. If `rmin` is greater than `rmax` the Y-axis of the array is reversed.

The parameter `phimin` and `phimax` can be used to map the data to a sector of the (punctured) disk starting at `phimin` and ending at `phimax`. If `phimin` is greater than `phimax` the X-axis is reversed. The visible sector is the one starting in mathematically positive direction (counterclockwise) at the smaller angle and ending at the larger angle. An example of the four possible options can be found below:

  • phimin phimax Result

  • 90 270 Left half visible, mapped counterclockwise

  • 270 90 Left half visible, mapped clockwise

  • -90 90 Right half visible, mapped counterclockwise

  • 90 -90 Right half visible, mapped clockwise

Calls superclass method
# File lib/gr.rb, line 370
def polarcellarray(x_org, y_org, phimin, phimax, rmin, rmax, dimphi, dimr, color)
  super(x_org, y_org, phimin, phimax, rmin, rmax, dimphi, dimr, 1, 1, dimphi, dimr, int(color))
end
polarheatmap(*args) click to toggle source

(Plot) Draw a polarheatmap.

# File lib/gr/plot.rb, line 1306
def polarheatmap(*args)
  d = args.shift
  # FIXME
  z = Numo::DFloat.cast(d)
  raise 'expected 2-D array' unless z.ndim == 2

  create_plot(:polarheatmap, z, *args) do |plt|
    width, height = z.shape
    plt.kvs[:xlim] ||= [0.5, width + 0.5]
    plt.kvs[:ylim] ||= [0.5, height + 0.5]
    plt.args = [[(1..width).to_a, (1..height).to_a, z, nil, '']]
  end
end
polarhistogram(x, kv = {}) click to toggle source

(Plot)

# File lib/gr/plot.rb, line 1282
def polarhistogram(x, kv = {})
  plt = GR::Plot.new(x, kv)
  plt.kvs[:kind] = :polarhist
  nbins = plt.kvs[:nbins] || 0
  x, y = hist(x, nbins)
  plt.args = [[x, y, nil, nil, '']]
  plt.plot_data
end
polyline(x, y, linewidth = nil, line_z = nil) click to toggle source

Draw a polyline using the current line attributes, starting from the first data point and ending at the last data point.

@param x [Array, NArray] A list containing the X coordinates @param y [Array, NArray] A list containing the Y coordinates @param linewidth [Array, NArray, Numeric] A list containing the line widths @param line_z [Array, NArray, Numeric] A list to be converted to colors

The values for x and y are in world coordinates. The attributes that control the appearance of a polyline are linetype, linewidth and color index.

Calls superclass method
# File lib/gr.rb, line 190
def polyline(x, y, linewidth = nil, line_z = nil)
  # GR.jl - Multiple dispatch
  n = equal_length(x, y)
  if linewidth.nil? && line_z.nil?
    super(n, x, y)
  else
    linewidth ||= GR.inqlinewidth
    linewidth = if linewidth.is_a?(Numeric)
                  Array.new(n, linewidth * 100)
                else
                  raise ArgumentError if n != linewidth.length

                  linewidth.map { |i| (100 * i).round }
                end
    line_z ||= GR.inqcolor(989) # FIXME
    color = if line_z.is_a?(Numeric)
              Array.new(n, line_z)
            else
              raise ArgumentError if n != line_z.length

              to_rgb_color(line_z)
            end
    z = linewidth.to_a.zip(color).flatten # to_a : NArray
    gdp(x, y, GDP_DRAW_LINES, z)
  end
end
polyline3d(x, y, z) click to toggle source

Draw a 3D curve using the current line attributes, starting from the first data point and ending at the last data point.

The values for `x`, `y` and `z` are in world coordinates. The attributes that control the appearance of a polyline are linetype, linewidth and color index.

@param x [Array, NArray] A list of length N containing the X coordinates @param y [Array, NArray] A list of length N containing the Y coordinates @param z [Array, NArray] A list of length N containing the Z coordinates

Calls superclass method
# File lib/gr.rb, line 1225
def polyline3d(x, y, z)
  n = equal_length(x, y, z)
  super(n, x, y, z)
end
polymarker(x, y, markersize = nil, marker_z = nil) click to toggle source

Draw marker symbols centered at the given data points.

@param x [Array, NArray] A list containing the X coordinates @param y [Array, NArray] A list containing the Y coordinates @param markersize [Array, NArray, Numeric] A list containing the marker sizes @param marker_z [Array, NArray, Numeric] A list to be converted to colors

The values for x and y are in world coordinates. The attributes that control the appearance of a polymarker are marker type, marker size scale factor and color index.

Calls superclass method
# File lib/gr.rb, line 228
def polymarker(x, y, markersize = nil, marker_z = nil)
  # GR.jl - Multiple dispatch
  n = equal_length(x, y)
  if markersize.nil? && marker_z.nil?
    super(n, x, y)
  else
    markersize ||= GR.inqmarkersize
    markersize = if markersize.is_a?(Numeric)
                   Array.new(n, markersize * 100)
                 else
                   raise ArgumentError if n != markersize.length

                   markersize.map { |i| (100 * i).round }
                 end
    marker_z ||= GR.inqcolor(989) # FIXME
    color = if marker_z.is_a?(Numeric)
              Array.new(n, marker_z)
            else
              raise ArgumentError if n != marker_z.length

              to_rgb_color(marker_z)
            end
    z = markersize.to_a.zip(color).flatten # to_a : NArray
    gdp(x, y, GDP_DRAW_MARKERS, z)
  end
end
polymarker3d(x, y, z) click to toggle source

Draw marker symbols centered at the given 3D data points.

The values for `x`, `y` and `z` are in world coordinates. The attributes that control the appearance of a polymarker are marker type, marker size scale factor and color index.

@param x [Array, NArray] A list of length N containing the X coordinates @param y [Array, NArray] A list of length N containing the Y coordinates @param z [Array, NArray] A list of length N containing the Z coordinates

Calls superclass method
# File lib/gr.rb, line 1240
def polymarker3d(x, y, z)
  n = equal_length(x, y, z)
  super(n, x, y, z)
end
quiver(x, y, u, v, color) click to toggle source

Draw a quiver plot on a grid of nx*ny points.

@param nx [Integer] The number of points along the x-axis of the grid @param ny [Integer] The number of points along the y-axis of the grid @param x [Array, NArray] A list containing the X coordinates @param y [Array, NArray] A list containing the Y coordinates @param u [Array, NArray] A list containing the U component for each point on the grid @param v [Array, NArray] A list containing the V component for each point on the grid @param color [Integer]

A bool to indicate whether or not the arrows should be colored using
the current colormap

The values for `x` and `y` are in world coordinates.

Calls superclass method
# File lib/gr.rb, line 1909
def quiver(x, y, u, v, color)
  # TODO: check: Arrays have incorrect length or dimension.
  nx = x.length
  ny = y.length
  super(nx, ny, x, y, u, v, (color ? 1 : 0))
end
readimage(path) click to toggle source

@return [Integer]

Calls superclass method
# File lib/gr.rb, line 1703
def readimage(path)
  # Feel free to make a pull request if you catch a mistake
  # or you have an idea to improve it.
  data = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INTPTR_T)
  w, h = inquiry [:int, :int] do |width, height|
    # data is a pointer of a pointer
    super(path, width, height, data.ref)
  end
  d = data.to_str(w * h * Fiddle::SIZEOF_INT).unpack('L*') # UInt32
  [w, h, d]
end
reducepoints(xd, yd, n) click to toggle source

Reduces the number of points of the x and y array.

@param n [Integer] The requested number of points @param x [Array, NArray] The x value array @param y [Array, NArray] The y value array

Calls superclass method
# File lib/gr.rb, line 1866
def reducepoints(xd, yd, n)
  nd = equal_length(xd, yd)
  inquiry [{ double: n }, { double: n }] do |x, y|
    # Different from Julia. x, y are initialized zero.
    super(nd, xd, yd, n, x, y)
  end
end
savefig(filename, kv = {}) click to toggle source

(Plot) Save the current figure to a file.

# File lib/gr/plot.rb, line 1476
def savefig(filename, kv = {})
  GR.beginprint(filename)
  plt = GR::Plot.last_plot
  plt.kvs.merge!(kv)
  plt.plot_data(false)
  GR.endprint
end
scatter(*args) click to toggle source

(Plot) Draw one or more scatter plots.

# File lib/gr/plot.rb, line 1272
def scatter(*args)
  create_plot(:scatter, *args)
end
scatter3(*args) click to toggle source

(Plot) Draw one or more three-dimensional scatter plots.

# File lib/gr/plot.rb, line 1384
def scatter3(*args)
  create_plot(:scatter3, *args)
end
setcolormapfromrgb(r, g, b, positions: nil) click to toggle source

Define a colormap by a list of RGB colors. @note GR.jl and python-gr have different APIsI

This function defines a colormap using the n given color intensities. If less than 256 colors are provided the colors intensities are linear interpolated. If x is NULL the given color values are evenly distributed in the colormap. Otherwise the normalized value of x defines the position of the color in the colormap.

@param r [Array, NArray] The red intensities in range 0.0 to 1.0 @param g [Array, NArray] The green intensities in range 0.0 to 1.0 @param b [Array, NArray] The blue intensities in range 0.0 to 1.0 @param positions [Array, NArray]

The positions of the corresponding color in the resulting colormap or nil.
The values of positions must increase monotonically from 0.0 to 1.0.
If positions is nil the given colors are evenly distributed in the colormap.
Calls superclass method
# File lib/gr.rb, line 1432
def setcolormapfromrgb(r, g, b, positions: nil)
  n = equal_length(r, g, b)
  if positions.nil?
    positions = Fiddle::NULL
  elsif positions.length != n
    raise
  end
  super(n, r, g, b, positions)
end
setcoordxform(mat) click to toggle source

Change the coordinate transformation according to the given matrix.

@param mat [Array, NArray] 2D transformation matrix

Calls superclass method
# File lib/gr.rb, line 1766
def setcoordxform(mat)
  raise if mat.size != 6

  super(mat)
end
shade(*args) click to toggle source

(Plot)

# File lib/gr/plot.rb, line 1390
def shade(*args)
  create_plot(:shade, *args)
end
Also aliased as: _shade_
shadelines(x, y, dims: [1200, 1200], xform: 1) click to toggle source

Display a line set as an aggregated and rasterized image.

The values for `x` and `y` are in world coordinates. NaN values can be used to separate the point set into line segments.

@param x [Array, NArray] A pointer to the X coordinates @param y [Array, NArray] A pointer to the Y coordinates @param dims [Array, NArray] The size of the grid used for rasterization @param xform [Integer] The transformation type used for color mapping

The available transformation types are:
* 0 : XFORM_BOOLEAN   - boolean
* 1 : XFORM_LINEAR    - linear
* 2 : XFORM_LOG       - logarithmic
* 3 : XFORM_LOGLOG    - double logarithmic
* 4 : XFORM_CUBIC     - cubic
* 5 : XFORM_EQUALIZED - histogram equalized
Calls superclass method
# File lib/gr.rb, line 1998
def shadelines(x, y, dims: [1200, 1200], xform: 1)
  n = x.length
  w, h = dims
  super(n, x, y, xform, w, h)
end
shadepoints(x, y, dims: [1200, 1200], xform: 1) click to toggle source

Display a point set as a aggregated and rasterized image.

The values for `x` and `y` are in world coordinates.

@param x [Array, NArray] A pointer to the X coordinates @param y [Array, NArray] A pointer to the Y coordinates @param dims [Array, NArray] The size of the grid used for rasterization @param xform [Integer] The transformation type used for color mapping

The available transformation types are:
* 0 : XFORM_BOOLEAN   - boolean
* 1 : XFORM_LINEAR    - linear
* 2 : XFORM_LOG       - logarithmic
* 3 : XFORM_LOGLOG    - double logarithmic
* 4 : XFORM_CUBIC     - cubic
* 5 : XFORM_EQUALIZED - histogram equalized
Calls superclass method
# File lib/gr.rb, line 1975
def shadepoints(x, y, dims: [1200, 1200], xform: 1)
  n = x.length
  w, h = dims
  super(n, x, y, xform, w, h)
end
spline(x, y, m, method) click to toggle source

Generate a cubic spline-fit, starting from the first data point and ending at the last data point.

@param x [Array, NArray] A list containing the X coordinates @param y [Array, NArray] A list containing the Y coordinates @param m [Integer] The number of points in the polygon to be

drawn (`m` > len(`x`))

@param method [Integer] The smoothing method

* If `method` is > 0, then a generalized cross-validated smoothing spline is calculated.
* If `method` is 0, then an interpolating natural cubic spline is calculated.
* If `method` is < -1, then a cubic B-spline is calculated.

The values for `x` and `y` are in world coordinates. The attributes that control the appearance of a spline-fit are linetype, linewidth and color index.

Calls superclass method
# File lib/gr.rb, line 426
def spline(x, y, m, method)
  n = equal_length(x, y)
  super(n, x, y, m, method)
end
stem(*args) click to toggle source

(Plot) Draw a stem plot.

# File lib/gr/plot.rb, line 1277
def stem(*args)
  create_plot(:stem, *args)
end
step(*args) click to toggle source

(Plot) Draw one or more step or staircase plots.

# File lib/gr/plot.rb, line 1267
def step(*args)
  create_plot(:step, *args)
end
subplot(nr, nc, p, kv = {}) click to toggle source

Set current subplot index.

# File lib/gr/plot.rb, line 1453
def subplot(nr, nc, p, kv = {})
  xmin = 1
  xmax = 0
  ymin = 1
  ymax = 0
  p = [p] if p.is_a? Integer
  p.each do |i|
    r = (nr - (i - 1) / nc).to_f
    c = ((i - 1) % nc + 1).to_f
    xmin = [xmin, (c - 1) / nc].min
    xmax = [xmax, c / nc].max
    ymin = [ymin, (r - 1) / nr].min
    ymax = [ymax, r / nr].max
  end
  {
    subplot: [xmin, xmax, ymin, ymax],
    # The policy of clearing when p[0]==1 is controversial
    clear: p[0] == 1,
    update: p[-1] == nr * nc
  }.merge kv
end
surface(x, y, z, option) click to toggle source

Draw a three-dimensional surface plot for the given data points.

`x` and `y` define a grid. `z` is a singly dimensioned array containing at least `nx` * `ny` data points. Z describes the surface height at each point on the grid. Data is ordered as shown in the table:

@note `surface` is overwritten by `require gr/plot`.

The original method is moved to the underscored name.
The yard document will show the method name after evacuation.

@param x [Array, NArray] A list containing the X coordinates @param y [Array, NArray] A list containing the Y coordinates @param z [Array, NArray]

A list of length `len(x)` * `len(y)` or an appropriately dimensioned
array containing the Z coordinates

@param option [Integer] Surface display option

* 0 LINES         - Use X Y polylines to denote the surface
* 1 MESH          - Use a wire grid to denote the surface
* 2 FILLED_MESH   - Applies an opaque grid to the surface
* 3 Z_SHADED_MESH - Applies Z-value shading to the surface
* 4 COLORED_MESH  - Applies a colored grid to the surface
* 5 CELL_ARRAY    - Applies a grid of individually-colored cells to the surface
* 6 SHADED_MESH   - Applies light source shading to the 3-D surface
Calls superclass method
# File lib/gr.rb, line 1317
def surface(x, y, z, option)
  # TODO: check: Arrays have incorrect length or dimension.
  nx = x.length
  ny = y.length
  super(nx, ny, x, y, z, option)
end
Also aliased as: _surface_
to_rgb_color(z) click to toggle source

@param z [Array, NArray] @return [Array, NArray]

# File lib/gr.rb, line 2111
def to_rgb_color(z)
  zmin, zmax = z.minmax
  return Array.new(z.length, 0) if zmax == zmin

  z.map  do |i|
    zi = (i - zmin) / (zmax - zmin).to_f
    inqcolor(1000 + (zi * 255).round)
  end
end
tricont(*args) click to toggle source

(Plot) Draw a triangular contour plot.

# File lib/gr/plot.rb, line 1353
def tricont(*args)
  create_plot(:tricont, *format_xyzc(*args))
end
tricontour(x, y, z, levels) click to toggle source

Draw a contour plot for the given triangle mesh.

@param x [Array, NArray] A list containing the X coordinates @param y [Array, NArray] A list containing the Y coordinates @param z [Array, NArray] A list containing the Z coordinates @param levels [Array, NArray] A list of contour levels

Calls superclass method
# File lib/gr.rb, line 1385
def tricontour(x, y, z, levels)
  npoints = x.length # equal_length ?
  nlevels = levels.length
  super(npoints, x, y, z, nlevels, levels)
end
trisurf(*args) click to toggle source

(Plot) Draw a triangular surface plot.

# File lib/gr/plot.rb, line 1374
def trisurf(*args)
  create_plot(:trisurf, *format_xyzc(*args))
end
trisurface(x, y, z) click to toggle source

Draw a triangular surface plot for the given data points.

@param x [Array, NArray] A list containing the X coordinates @param y [Array, NArray] A list containing the Y coordinates @param z [Array, NArray] A list containing the Z coordinates

Calls superclass method
# File lib/gr.rb, line 1880
def trisurface(x, y, z)
  n = [x, y, z].map(&:length).min
  super(n, x, y, z)
end
verrorbars(x, y, e1, e2) click to toggle source

Draw a standard vertical error bar graph.

@param x [Array, NArray] A list of length N containing the X coordinates @param y [Array, NArray] A list of length N containing the Y coordinates @param e1 [Array, NArray] The absolute values of the lower error bar data @param e2 [Array, NArray] The absolute values of the lower error bar data

Calls superclass method
# File lib/gr.rb, line 1197
def verrorbars(x, y, e1, e2)
  n = equal_length(x, y, e1, e2)
  super(n, x, y, e1, e2)
end
version() click to toggle source

Returns the combined version strings of the GR runtime.

@return [String]

Calls superclass method
# File lib/gr.rb, line 1949
def version
  super.to_s
end
volume(v, kv = {}) click to toggle source

(Plot)

# File lib/gr/plot.rb, line 1395
def volume(v, kv = {})
  create_plot(:volume, v, kv) do |plt|
    plt.args = [[nil, nil, v, nil, '']]
  end
end
wc3towc(x, y, z) click to toggle source
Calls superclass method
# File lib/gr.rb, line 1578
def wc3towc(x, y, z)
  inquiry %i[double double double] do |px, py, pz|
    px.write_double x
    py.write_double y
    pz.write_double z
    super(px, py, pz)
  end
end
wctondc(x, y) click to toggle source
Calls superclass method
# File lib/gr.rb, line 1570
def wctondc(x, y)
  inquiry %i[double double] do |px, py|
    px.write_double x
    py.write_double y
    super(px, py)
  end
end
wireframe(*args) click to toggle source

(Plot) Draw a three-dimensional wireframe plot.

# File lib/gr/plot.rb, line 1358
def wireframe(*args)
  create_plot(:wireframe, *format_xyzc(*args))
end

Private Class Methods

barcoordinates(heights, barwidth = 0.8, baseline = 0.0) click to toggle source
# File lib/gr/plot.rb, line 1537
def barcoordinates(heights, barwidth = 0.8, baseline = 0.0)
  halfw = barwidth / 2.0
  wc = []
  hc = []
  heights.each_with_index do |value, i|
    wc << i - halfw
    wc << i + halfw
    hc << baseline
    hc << value
  end
  [wc, hc]
end
create_plot(type, *args) { |plt| ... } click to toggle source
# File lib/gr/plot.rb, line 1486
def create_plot(type, *args)
  plt = GR::Plot.new(*args)
  plt.kvs[:kind] = type
  yield(plt) if block_given?
  plt.plot_data
  plt
end
format_xyzc(*args) click to toggle source
# File lib/gr/plot.rb, line 1494
def format_xyzc(*args)
  kv = if args[-1].is_a? Hash
         args.pop
       else
         {}
       end

  args = [args] unless args.all? do |i|
                         i.is_a?(Array) && (i[0].is_a?(Array) || narray?(i[0]))
                       end
  args.map! do |xyzc|
    if xyzc.size == 1
      if xyzc[0].is_a? Array
        z = Numo::DFloat.cast(xyzc[0])
      elsif narray?(xyzc[0])
        z = xyzc[0]
      end
      xsize, ysize = z.shape
      x = (1..ysize).to_a * xsize
      y = (1..xsize).map { |i| Array.new(ysize, i) }.flatten
      [x, y, z]
    else

      xyzc
    end
  end
  [*args, kv]
end
hist(x, nbins = 0) click to toggle source
# File lib/gr/plot.rb, line 1523
def hist(x, nbins = 0)
  nbins = (3.3 * Math.log10(x.length)).round + 1 if nbins <= 1
  begin
    require 'histogram/array'
  rescue LoadError => e
    e.message << " Please add gem 'histogram' to your project's Gemfile."
    raise e
  end
  x = x.to_a if narray?(x)
  x, y = x.histogram(nbins, bin_boundary: :min)
  x.push(x[-1] + x[1] - x[0])
  [x, y]
end