Module: GR

Defined in:
lib/gr/plot.rb,
lib/gr/plot/version.rb

Defined Under Namespace

Classes: Plot

Class Method Summary collapse

Class Method Details

._contour_Object



1414
# File 'lib/gr/plot.rb', line 1414

alias _contour_ contour

._contourf_Object



1420
# File 'lib/gr/plot.rb', line 1420

alias _contourf_ contourf

._hexbin_Object



1426
# File 'lib/gr/plot.rb', line 1426

alias _hexbin_ hexbin

._shade_Object



1468
# File 'lib/gr/plot.rb', line 1468

alias _shade_ shade

._surface_Object

(Plot) Draw a three-dimensional surface plot.



1443
# File 'lib/gr/plot.rb', line 1443

alias _surface_ surface

.barplot(labels, heights, kv = {}) ⇒ Object

(Plot) Draw a bar plot.



1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
# File 'lib/gr/plot.rb', line 1482

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

.contour(*args) ⇒ Object

(Plot) Draw a contour plot.



1416
1417
1418
# File 'lib/gr/plot.rb', line 1416

def contour(*args)
  create_plot(:contour, *format_xyzc(*args))
end

.contourf(*args) ⇒ Object

(Plot) Draw a filled contour plot.



1422
1423
1424
# File 'lib/gr/plot.rb', line 1422

def contourf(*args)
  create_plot(:contourf, *format_xyzc(*args))
end

.heatmap(*args) ⇒ Object

(Plot) Draw a heatmap.



1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
# File 'lib/gr/plot.rb', line 1372

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

.hexbin(*args) ⇒ Object

(Plot) Draw a hexagon binning plot.



1428
1429
1430
# File 'lib/gr/plot.rb', line 1428

def hexbin(*args)
  create_plot(:hexbin, *args)
end

.histogram(series, kv = {}) ⇒ Object

(Plot) Draw a histogram.



1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
# File 'lib/gr/plot.rb', line 1499

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) ⇒ Object



1527
1528
1529
1530
# File 'lib/gr/plot.rb', line 1527

def hold(flag = true)
  plt = GR::Plot.last_plot
  plt.kvs.slice(:window, :scale, :xaxis, :yaxis, :zaxis).merge({ ax: flag, clear: !flag })
end

.imshow(img, kv = {}) ⇒ Object

(Plot) Draw an image.



1512
1513
1514
1515
1516
1517
# File 'lib/gr/plot.rb', line 1512

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

.isosurface(v, kv = {}) ⇒ Object

(Plot) Draw an isosurface.



1520
1521
1522
1523
1524
1525
# File 'lib/gr/plot.rb', line 1520

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

.nonuniformpolarheatmap(*args) ⇒ Object

(Plot) Draw a nonuniformpolarheatmap.



1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
# File 'lib/gr/plot.rb', line 1401

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

.plot(*args) ⇒ Object

(Plot) Draw one or more line plots.



1342
1343
1344
# File 'lib/gr/plot.rb', line 1342

def plot(*args)
  create_plot(:line, *args)
end

.plot3(*args) ⇒ Object

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



1459
1460
1461
# File 'lib/gr/plot.rb', line 1459

def plot3(*args)
  create_plot(:plot3, *args)
end

.polar(*args) ⇒ Object

(Plot)



1449
1450
1451
# File 'lib/gr/plot.rb', line 1449

def polar(*args)
  create_plot(:polar, *args)
end

.polarheatmap(*args) ⇒ Object

(Plot) Draw a polarheatmap.



1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
# File 'lib/gr/plot.rb', line 1386

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 = {}) ⇒ Object

(Plot)



1362
1363
1364
1365
1366
1367
1368
1369
# File 'lib/gr/plot.rb', line 1362

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

.savefig(filename, kv = {}) ⇒ Object

(Plot) Save the current figure to a file.



1556
1557
1558
1559
1560
1561
1562
# File 'lib/gr/plot.rb', line 1556

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) ⇒ Object

(Plot) Draw one or more scatter plots.



1352
1353
1354
# File 'lib/gr/plot.rb', line 1352

def scatter(*args)
  create_plot(:scatter, *args)
end

.scatter3(*args) ⇒ Object

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



1464
1465
1466
# File 'lib/gr/plot.rb', line 1464

def scatter3(*args)
  create_plot(:scatter3, *args)
end

.shade(*args) ⇒ Object

(Plot)



1470
1471
1472
# File 'lib/gr/plot.rb', line 1470

def shade(*args)
  create_plot(:shade, *args)
end

.stem(*args) ⇒ Object

(Plot) Draw a stem plot.



1357
1358
1359
# File 'lib/gr/plot.rb', line 1357

def stem(*args)
  create_plot(:stem, *args)
end

.step(*args) ⇒ Object

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



1347
1348
1349
# File 'lib/gr/plot.rb', line 1347

def step(*args)
  create_plot(:step, *args)
end

.subplot(nr, nc, p, kv = {}) ⇒ Object

Set current subplot index.



1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
# File 'lib/gr/plot.rb', line 1533

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(*args) ⇒ Object



1444
1445
1446
# File 'lib/gr/plot.rb', line 1444

def surface(*args)
  create_plot(:surface, *format_xyzc(*args))
end

.tricont(*args) ⇒ Object

(Plot) Draw a triangular contour plot.



1433
1434
1435
# File 'lib/gr/plot.rb', line 1433

def tricont(*args)
  create_plot(:tricont, *format_xyzc(*args))
end

.trisurf(*args) ⇒ Object

(Plot) Draw a triangular surface plot.



1454
1455
1456
# File 'lib/gr/plot.rb', line 1454

def trisurf(*args)
  create_plot(:trisurf, *format_xyzc(*args))
end

.volume(v, kv = {}) ⇒ Object

(Plot)



1475
1476
1477
1478
1479
# File 'lib/gr/plot.rb', line 1475

def volume(v, kv = {})
  create_plot(:volume, v, kv) do |plt|
    plt.args = [[nil, nil, v, nil, '']]
  end
end

.wireframe(*args) ⇒ Object

(Plot) Draw a three-dimensional wireframe plot.



1438
1439
1440
# File 'lib/gr/plot.rb', line 1438

def wireframe(*args)
  create_plot(:wireframe, *format_xyzc(*args))
end