Module: GR
- Defined in:
- lib/gr/plot.rb,
lib/gr/plot/version.rb
Defined Under Namespace
Classes: Plot
Class Method Summary collapse
- ._contour_ ⇒ Object
- ._contourf_ ⇒ Object
- ._hexbin_ ⇒ Object
- ._shade_ ⇒ Object
-
._surface_ ⇒ Object
(Plot) Draw a three-dimensional surface plot.
-
.barplot(labels, heights, kv = {}) ⇒ Object
(Plot) Draw a bar plot.
-
.contour(*args) ⇒ Object
(Plot) Draw a contour plot.
-
.contourf(*args) ⇒ Object
(Plot) Draw a filled contour plot.
-
.heatmap(*args) ⇒ Object
(Plot) Draw a heatmap.
-
.hexbin(*args) ⇒ Object
(Plot) Draw a hexagon binning plot.
-
.histogram(series, kv = {}) ⇒ Object
(Plot) Draw a histogram.
- .hold(flag = true) ⇒ Object
-
.imshow(img, kv = {}) ⇒ Object
(Plot) Draw an image.
-
.isosurface(v, kv = {}) ⇒ Object
(Plot) Draw an isosurface.
-
.nonuniformpolarheatmap(*args) ⇒ Object
(Plot) Draw a nonuniformpolarheatmap.
-
.plot(*args) ⇒ Object
(Plot) Draw one or more line plots.
-
.plot3(*args) ⇒ Object
(Plot) Draw one or more three-dimensional line plots.
-
.polar(*args) ⇒ Object
(Plot).
-
.polarheatmap(*args) ⇒ Object
(Plot) Draw a polarheatmap.
-
.polarhistogram(x, kv = {}) ⇒ Object
(Plot).
-
.savefig(filename, kv = {}) ⇒ Object
(Plot) Save the current figure to a file.
-
.scatter(*args) ⇒ Object
(Plot) Draw one or more scatter plots.
-
.scatter3(*args) ⇒ Object
(Plot) Draw one or more three-dimensional scatter plots.
-
.shade(*args) ⇒ Object
(Plot).
-
.stem(*args) ⇒ Object
(Plot) Draw a stem plot.
-
.step(*args) ⇒ Object
(Plot) Draw one or more step or staircase plots.
-
.subplot(nr, nc, p, kv = {}) ⇒ Object
Set current subplot index.
- .surface(*args) ⇒ Object
-
.tricont(*args) ⇒ Object
(Plot) Draw a triangular contour plot.
-
.trisurf(*args) ⇒ Object
(Plot) Draw a triangular surface plot.
-
.volume(v, kv = {}) ⇒ Object
(Plot).
-
.wireframe(*args) ⇒ Object
(Plot) Draw a three-dimensional wireframe plot.
Class Method Details
._contour_ ⇒ Object
1337 |
# File 'lib/gr/plot.rb', line 1337 alias _contour_ contour |
._contourf_ ⇒ Object
1343 |
# File 'lib/gr/plot.rb', line 1343 alias _contourf_ contourf |
._hexbin_ ⇒ Object
1349 |
# File 'lib/gr/plot.rb', line 1349 alias _hexbin_ hexbin |
._shade_ ⇒ Object
1391 |
# File 'lib/gr/plot.rb', line 1391 alias _shade_ shade |
._surface_ ⇒ Object
(Plot) Draw a three-dimensional surface plot.
1366 |
# File 'lib/gr/plot.rb', line 1366 alias _surface_ surface |
.barplot(labels, heights, kv = {}) ⇒ Object
(Plot) Draw a bar plot.
1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 |
# File 'lib/gr/plot.rb', line 1405 def (labels, heights, kv = {}) labels = labels.map(&:to_s) wc, hc = (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.
1339 1340 1341 |
# File 'lib/gr/plot.rb', line 1339 def contour(*args) create_plot(:contour, *format_xyzc(*args)) end |
.contourf(*args) ⇒ Object
(Plot) Draw a filled contour plot.
1345 1346 1347 |
# File 'lib/gr/plot.rb', line 1345 def contourf(*args) create_plot(:contourf, *format_xyzc(*args)) end |
.heatmap(*args) ⇒ Object
(Plot) Draw a heatmap.
1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 |
# File 'lib/gr/plot.rb', line 1295 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.
1351 1352 1353 |
# File 'lib/gr/plot.rb', line 1351 def hexbin(*args) create_plot(:hexbin, *args) end |
.histogram(series, kv = {}) ⇒ Object
(Plot) Draw a histogram.
1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 |
# File 'lib/gr/plot.rb', line 1422 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
1450 1451 1452 1453 |
# File 'lib/gr/plot.rb', line 1450 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.
1435 1436 1437 1438 1439 1440 |
# File 'lib/gr/plot.rb', line 1435 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.
1443 1444 1445 1446 1447 1448 |
# File 'lib/gr/plot.rb', line 1443 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.
1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 |
# File 'lib/gr/plot.rb', line 1324 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.
1265 1266 1267 |
# File 'lib/gr/plot.rb', line 1265 def plot(*args) create_plot(:line, *args) end |
.plot3(*args) ⇒ Object
(Plot) Draw one or more three-dimensional line plots.
1382 1383 1384 |
# File 'lib/gr/plot.rb', line 1382 def plot3(*args) create_plot(:plot3, *args) end |
.polar(*args) ⇒ Object
(Plot)
1372 1373 1374 |
# File 'lib/gr/plot.rb', line 1372 def polar(*args) create_plot(:polar, *args) end |
.polarheatmap(*args) ⇒ Object
(Plot) Draw a polarheatmap.
1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 |
# File 'lib/gr/plot.rb', line 1309 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)
1285 1286 1287 1288 1289 1290 1291 1292 |
# File 'lib/gr/plot.rb', line 1285 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.
1479 1480 1481 1482 1483 1484 1485 |
# File 'lib/gr/plot.rb', line 1479 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.
1275 1276 1277 |
# File 'lib/gr/plot.rb', line 1275 def scatter(*args) create_plot(:scatter, *args) end |
.scatter3(*args) ⇒ Object
(Plot) Draw one or more three-dimensional scatter plots.
1387 1388 1389 |
# File 'lib/gr/plot.rb', line 1387 def scatter3(*args) create_plot(:scatter3, *args) end |
.shade(*args) ⇒ Object
(Plot)
1393 1394 1395 |
# File 'lib/gr/plot.rb', line 1393 def shade(*args) create_plot(:shade, *args) end |
.stem(*args) ⇒ Object
(Plot) Draw a stem plot.
1280 1281 1282 |
# File 'lib/gr/plot.rb', line 1280 def stem(*args) create_plot(:stem, *args) end |
.step(*args) ⇒ Object
(Plot) Draw one or more step or staircase plots.
1270 1271 1272 |
# File 'lib/gr/plot.rb', line 1270 def step(*args) create_plot(:step, *args) end |
.subplot(nr, nc, p, kv = {}) ⇒ Object
Set current subplot index.
1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 |
# File 'lib/gr/plot.rb', line 1456 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
1367 1368 1369 |
# File 'lib/gr/plot.rb', line 1367 def surface(*args) create_plot(:surface, *format_xyzc(*args)) end |
.tricont(*args) ⇒ Object
(Plot) Draw a triangular contour plot.
1356 1357 1358 |
# File 'lib/gr/plot.rb', line 1356 def tricont(*args) create_plot(:tricont, *format_xyzc(*args)) end |
.trisurf(*args) ⇒ Object
(Plot) Draw a triangular surface plot.
1377 1378 1379 |
# File 'lib/gr/plot.rb', line 1377 def trisurf(*args) create_plot(:trisurf, *format_xyzc(*args)) end |
.volume(v, kv = {}) ⇒ Object
(Plot)
1398 1399 1400 1401 1402 |
# File 'lib/gr/plot.rb', line 1398 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.
1361 1362 1363 |
# File 'lib/gr/plot.rb', line 1361 def wireframe(*args) create_plot(:wireframe, *format_xyzc(*args)) end |