Module: GR
- Defined in:
- lib/gr/plot.rb,
lib/gr/plot/version.rb,
lib/gr/plot/histogram.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(*args) ⇒ 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.
-
.nonuniformheatmap(*args) ⇒ Object
(Plot) Draw a nonuniformheatmap.
-
.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).
-
.stairs(*args) ⇒ Object
(Plot) Draw one or more step or staircase plots.
-
.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
1666 |
# File 'lib/gr/plot.rb', line 1666 alias _contour_ contour |
._contourf_ ⇒ Object
1672 |
# File 'lib/gr/plot.rb', line 1672 alias _contourf_ contourf |
._hexbin_ ⇒ Object
1678 |
# File 'lib/gr/plot.rb', line 1678 alias _hexbin_ hexbin |
._shade_ ⇒ Object
1720 |
# File 'lib/gr/plot.rb', line 1720 alias _shade_ shade |
._surface_ ⇒ Object
(Plot) Draw a three-dimensional surface plot.
1695 |
# File 'lib/gr/plot.rb', line 1695 alias _surface_ surface |
.barplot(*args) ⇒ Object
(Plot) Draw a bar plot.
1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 |
# File 'lib/gr/plot.rb', line 1734 def (*args) kv = args.last.is_a?(Hash) ? args.pop : {} if args.length == 2 labels, heights = args elsif args.length == 1 heights = args[0] labels = (1..heights.length).map(&:to_s) else raise ArgumentError end wc, hc = (heights, kv) horizontal = kv.delete(:horizontal) create_plot(:bar, kv) do |plt| if horizontal plt.args = [[hc, wc, nil, nil, '']] plt.kvs[:yticks] = [1, 1] plt.kvs[:yticklabels] = labels.map(&:to_s) else plt.args = [[wc, hc, nil, nil, '']] plt.kvs[:xticks] = [1, 1] plt.kvs[:xticklabels] = labels.map(&:to_s) end end end |
.contour(*args) ⇒ Object
(Plot) Draw a contour plot.
1668 1669 1670 |
# File 'lib/gr/plot.rb', line 1668 def contour(*args) create_plot(:contour, *format_xyzc(*args)) end |
.contourf(*args) ⇒ Object
(Plot) Draw a filled contour plot.
1674 1675 1676 |
# File 'lib/gr/plot.rb', line 1674 def contourf(*args) create_plot(:contourf, *format_xyzc(*args)) end |
.heatmap(*args) ⇒ Object
(Plot) Draw a heatmap. (Plot) Draw a heatmap.
1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 |
# File 'lib/gr/plot.rb', line 1583 def heatmap(*args) kv = args.last.is_a?(Hash) ? args.pop : {} if args.length == 1 z = args[0] z = Numo::DFloat.cast(z) if z.is_a?(Array) ysize, xsize = z.shape z = z.reshape(xsize, ysize) x = (1..xsize).to_a y = (1..ysize).to_a elsif args.length == 3 x, y, z = args z = Numo::DFloat.cast(z) if z.is_a?(Array) else raise ArgumentError end create_plot(:heatmap, kv) do |plt| plt.args = [[x, y, z, nil, '']] end end |
.hexbin(*args) ⇒ Object
(Plot) Draw a hexagon binning plot.
1680 1681 1682 |
# File 'lib/gr/plot.rb', line 1680 def hexbin(*args) create_plot(:hexbin, *args) end |
.histogram(series, kv = {}) ⇒ Object
(Plot) Draw a histogram.
1762 1763 1764 1765 1766 1767 1768 |
# File 'lib/gr/plot.rb', line 1762 def histogram(series, kv = {}) create_plot(:hist, series, kv) do |plt| nbins = plt.kvs[:nbins] || 0 x, y = hist(series, nbins) plt.args = [[x, y, nil, nil, '']] end end |
.hold(flag = true) ⇒ Object
1786 1787 1788 1789 |
# File 'lib/gr/plot.rb', line 1786 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.
1771 1772 1773 1774 1775 1776 |
# File 'lib/gr/plot.rb', line 1771 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.
1779 1780 1781 1782 1783 1784 |
# File 'lib/gr/plot.rb', line 1779 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 |
.nonuniformheatmap(*args) ⇒ Object
(Plot) Draw a nonuniformheatmap.
1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 |
# File 'lib/gr/plot.rb', line 1604 def nonuniformheatmap(*args) kv = args.last.is_a?(Hash) ? args.pop : {} if args.length == 1 z = args[0] z = Numo::DFloat.cast(z) if z.is_a?(Array) ysize, xsize = z.shape z = z.reshape(xsize, ysize) x = (1..xsize).to_a y = (1..ysize).to_a elsif args.length == 3 x, y, z = args z = Numo::DFloat.cast(z) if z.is_a?(Array) else raise ArgumentError end create_plot(:nonuniformheatmap, kv) do |plt| plt.args = [[x, y, z, nil, '']] end end |
.nonuniformpolarheatmap(*args) ⇒ Object
(Plot) Draw a nonuniformpolarheatmap.
1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 |
# File 'lib/gr/plot.rb', line 1646 def nonuniformpolarheatmap(*args) kv = args.last.is_a?(Hash) ? args.pop : {} if args.length == 1 z = args[0] z = Numo::DFloat.cast(z) if z.is_a?(Array) ysize, xsize = z.shape z = z.reshape(xsize, ysize) x = (1..xsize).to_a y = (1..ysize).to_a elsif args.length == 3 x, y, z = args z = Numo::DFloat.cast(z) if z.is_a?(Array) else raise ArgumentError end create_plot(:nonuniformpolarheatmap, kv) do |plt| plt.args = [[x, y, z, nil, '']] end end |
.plot(*args) ⇒ Object
(Plot) Draw one or more line plots.
1547 1548 1549 |
# File 'lib/gr/plot.rb', line 1547 def plot(*args) create_plot(:line, *args) end |
.plot3(*args) ⇒ Object
(Plot) Draw one or more three-dimensional line plots.
1711 1712 1713 |
# File 'lib/gr/plot.rb', line 1711 def plot3(*args) create_plot(:plot3, *args) end |
.polar(*args) ⇒ Object
(Plot)
1701 1702 1703 |
# File 'lib/gr/plot.rb', line 1701 def polar(*args) create_plot(:polar, *args) end |
.polarheatmap(*args) ⇒ Object
(Plot) Draw a polarheatmap.
1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 |
# File 'lib/gr/plot.rb', line 1625 def polarheatmap(*args) kv = args.last.is_a?(Hash) ? args.pop : {} if args.length == 1 z = args[0] z = Numo::DFloat.cast(z) if z.is_a?(Array) ysize, xsize = z.shape z = z.reshape(xsize, ysize) x = (1..xsize).to_a y = (1..ysize).to_a elsif args.length == 3 x, y, z = args z = Numo::DFloat.cast(z) if z.is_a?(Array) else raise ArgumentError end create_plot(:polarheatmap, kv) do |plt| plt.args = [[x, y, z, nil, '']] end end |
.polarhistogram(x, kv = {}) ⇒ Object
(Plot)
1572 1573 1574 1575 1576 1577 1578 1579 |
# File 'lib/gr/plot.rb', line 1572 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.
1815 1816 1817 1818 1819 1820 1821 |
# File 'lib/gr/plot.rb', line 1815 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.
1562 1563 1564 |
# File 'lib/gr/plot.rb', line 1562 def scatter(*args) create_plot(:scatter, *args) end |
.scatter3(*args) ⇒ Object
(Plot) Draw one or more three-dimensional scatter plots.
1716 1717 1718 |
# File 'lib/gr/plot.rb', line 1716 def scatter3(*args) create_plot(:scatter3, *args) end |
.shade(*args) ⇒ Object
(Plot)
1722 1723 1724 |
# File 'lib/gr/plot.rb', line 1722 def shade(*args) create_plot(:shade, *args) end |
.stairs(*args) ⇒ Object
(Plot) Draw one or more step or staircase plots.
1557 1558 1559 |
# File 'lib/gr/plot.rb', line 1557 def stairs(*args) create_plot(:stairs, *args) end |
.stem(*args) ⇒ Object
(Plot) Draw a stem plot.
1567 1568 1569 |
# File 'lib/gr/plot.rb', line 1567 def stem(*args) create_plot(:stem, *args) end |
.step(*args) ⇒ Object
(Plot) Draw one or more step or staircase plots.
1552 1553 1554 |
# File 'lib/gr/plot.rb', line 1552 def step(*args) create_plot(:step, *args) end |
.subplot(nr, nc, p, kv = {}) ⇒ Object
Set current subplot index.
1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 |
# File 'lib/gr/plot.rb', line 1792 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
1696 1697 1698 |
# File 'lib/gr/plot.rb', line 1696 def surface(*args) create_plot(:surface, *format_xyzc(*args)) end |
.tricont(*args) ⇒ Object
(Plot) Draw a triangular contour plot.
1685 1686 1687 |
# File 'lib/gr/plot.rb', line 1685 def tricont(*args) create_plot(:tricont, *format_xyzc(*args)) end |
.trisurf(*args) ⇒ Object
(Plot) Draw a triangular surface plot.
1706 1707 1708 |
# File 'lib/gr/plot.rb', line 1706 def trisurf(*args) create_plot(:trisurf, *format_xyzc(*args)) end |
.volume(v, kv = {}) ⇒ Object
(Plot)
1727 1728 1729 1730 1731 |
# File 'lib/gr/plot.rb', line 1727 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.
1690 1691 1692 |
# File 'lib/gr/plot.rb', line 1690 def wireframe(*args) create_plot(:wireframe, *format_xyzc(*args)) end |