-
-
Notifications
You must be signed in to change notification settings - Fork 7
Multiple subplots
kojix2 edited this page Jun 26, 2020
·
15 revisions
You can use the subplot
method.
require 'gr/plot'
x = [1,2,3,4,5,6,7,8,9,10]
y = x.shuffle
GR.barplot x, y, GR.subplot(2, 2, 1)
GR.stem x, y, GR.subplot(2, 2, 2)
GR.step x, y, GR.subplot(2, 2, 3)
GR.plot x, y, GR.subplot(2, 2, 4)
require 'gr/plot'
x = [1,2,3,4,5,6,7,8,9,10]
y = x.shuffle
GR.scatter x, y, GR.subplot(5, 5, [2, 4])
GR.plot x, y, GR.subplot(5, 5, [6, 16])
GR.step x, y, GR.subplot(5, 5, [10, 20])
GR.barplot x, y, GR.subplot(5, 5, [7, 19])
GR.stem x, y, GR.subplot(5, 5, [22, 24], update: true)
subplot
returns a simple hash like this.
GR.subplot(2,2,1)
=> {:subplot=>[0.0, 0.5, 0.5, 1.0], :clear=>true, :update=>false}
Why does the GR.rb subplot simply return a Hash, unlike GR.jl? This is because the position of the subplot is better when it can be fine-tuned by a human being. Tweak the position of the subplot by changing the numbers in the Hash.
The update and clear flag are determined by these simple rules.
- if n==1
clear=>true
elseclear=>false
- if n==end
update=>true
elseupdate=>false
require 'gr/plot'
DFloat = Numo::DFloat
ax = DFloat.new(20_000).rand_norm
ay = DFloat.new(20_000).rand_norm
bx = DFloat.new(20_000).rand_norm(3)
by = DFloat.new(20_000).rand_norm(3)
cx = DFloat.new(20_000).rand_norm(3)
cy = DFloat.new(20_000).rand_norm(-3)
x = DFloat.hstack [ax, bx, cx]
y = DFloat.hstack [ay, by, cy]
GR.shade x, y, subplot: [0.02, 0.2, 0.8, 0.98], clear: true, update: false
GR.histogram x, subplot: [0.135, 0.89, 0.8, 0.98], clear: false, nbins: 50, update: false
GR.histogram y, subplot: [0.02, 0.2, 0.0, 0.82], horizontal: true, xflip: true, nbins: 50, grid: false, clear: false, update: false
GR.hexbin x, y, subplot: [0.12, 1.0, 0.0, 0.82], clear: false, update: true
sleep 1.5
User's Guide
Simple, matlab-style API
- Plotting functions
- Plot attributes
- Multiple plots
- Multiple subplots
- Save Plot to a file
- Jupyter Notebook
GR Native functions
For developers