Skip to content
kojix2 edited this page Jun 20, 2020 · 53 revisions
  • Currently the plot attributes are provided as a keyword argument.
  • This page is besed on GRUtils.jl.

Getting ready

We will add keyword arguments to two simple graphs: one is a simple 2D line plot and the other is a 3D wireframe. Here, we use Rdatasets Gem to load the data.

Simple 2D line plot

require 'gr/plot'
require 'rdatasets'

passenger = RDatasets.load(:datasets, :AirPassengers)
time = passenger["time"]
value = passenger["value"]

GR.plot(time, value)

plain

Simple 3D wireframe

volcano = RDatasets.datasets.volcano.to_matrix.to_a.transpose
volcano = Numo::DFloat.cast(volcano)

GR.wireframe(volcano)

volcano

Axis guides

title

Set the plot title as the string.

GR.plot(time, value, title: 'Air Passenger numbers from 1949 to 1961')

title

figsize

GR.plot(time, value, figsize: [1, 1])

figsize

GR.plot(time, value, figsize: [6, 2])

figsize

size

Set the approximate size of the window on the screen to be displayed in pixel size. The default size is [600, 450].

GR.plot(time, value, size: [480, 360])

size

xlabel, ylabel, zlabel

Set the X, Y or Z axis labels as the string.

GR.plot(time, value,
        title: 'Air Passenger numbers from 1949 to 1961',
        xlabel: 'Date',
        ylabel: "Passenger numbers (1000's)")

xlabel and ylabel

GR.wireframe(volcano, title: "Maunga Whau (Mt Eden)",
                      xlabel: "X", ylabel: "Y", zlabel: "Z")

xyzlabels

grid

Draw or disable the grid of the current plot axes.

GR.plot(time, value, grid: false)

grid

GR.wireframe(volcano, grid: false)

grid

xticks yticks zticks

Set the minor intervals of the ticks for the X, Y or Z axis, and (optionally) the number of minor ticks between major ticks.

GR.plot(time, value, xticks:[0.5, 4], yticks: [50, 2])

xtics 2D

GR.wireframe(volcano, xlabel: "X", ylabel: "Y", zlabel: "Z",
                      xticks: 11,  yticks: 13,  zticks: 17)

xtics 3D

xticklabels yticklabels

  • Under development

Axis dimensions

xlim ylim zlim

Set the limits for the plot axes.

GR.plot(time, value, ylim: [0, 4000], xlim: [1920, 2020])

lim

GR.wireframe(volcano, zlim: [80, 120])

lim

GR.wireframe(volcano.clip(80,120), zlim: [80, 120])

image

panzoom

Pan/zoom the axes of the current plot.

3-D views

viewport

Set the viewpoint of three-dimensional plots.

rotation

Rotate the viewpoint of the current plot by angle degrees around the vertical axis of the scene, with respect to its current position.

30.times do |i|
  GR.wireframe(volcano, rotation: i * 3)
end

rotation

tilt

Tilt (elevate) the viewpoint of the current plot by angle degrees over the horizontal plane, with respect to its current position.

30.times { |i|  GR.wireframe(volcano, tilt: i * 3) }
30.times { |i|  GR.wireframe(volcano, tilt: 90 - i * 3) }

tilt

Not implemented: movefocus, turncamera

Axis scales

xflip, yflip, zflip

Reverse the direction of the X-axis, Y-axis or Z-axis, or set them back to their normal direction.

GR.plot time, value, GR.subplot(2,2,1, xflip: false, yflip: false, label: "default",    location: 2)
GR.plot time, value, GR.subplot(2,2,2, xflip: true,  yflip: false, label: "x flipped",  location: 1)
GR.plot time, value, GR.subplot(2,2,3, xflip: false, yflip: true , label: "y fipped",   location: 3)
GR.plot time, value, GR.subplot(2,2,4, xflip: true,  yflip: true , label: "x,y fipped", location: 4)

flip

xlog, ylog, zlog

Set the X-axis, Y-axis or Z-axis to be drawn in logarithmic scale, or in linear scale.

Not implemented: radians

Geometry guides

location

Set the legend of the plot, using a series of labels.

  • 0 "none"
  • 1 "upper right"
  • 2 "upper left"
  • 3 "lower left"
  • 4 "lower right"
  • 5 "right"
  • 6 "center left"
  • 7 "center right"
  • 8 "lower center"
  • 9 "upper center"
  • 10 "center"
  • 11 "outer upper right"
  • 12 "outer center right"
  • 13 "outer lower right"

In GRUtils legend

Not implemented: geometrykinds, colorbar

Colors

background

Add a custom background color to the current figure.

colormap

Set or retrieve the values of the current colormap.

colorscheme