Skip to content

Commit 47f9d1f

Browse files
committed
Update plot.rb
1 parent 24ec10f commit 47f9d1f

File tree

1 file changed

+74
-32
lines changed

1 file changed

+74
-32
lines changed

lib/gr/plot.rb

Lines changed: 74 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,9 +1138,14 @@ def plot_data(_figure = true)
11381138

11391139
when :volume
11401140
algorithm = kvs[:algorithm] || 0
1141+
w, h, ratio = GR.inqvpsize
1142+
GR.setpicturesizeforvolume((w * ratio).round, (h * ratio).round)
11411143
require 'gr3'
11421144
GR3.clear
1145+
ambient, diffuse, specular, specular_power = GR3.getlightparameters
1146+
GR3.setlightparameters(0.8, 0.2, 0.1, 10.0)
11431147
dmin, dmax = GR3.volume(z, algorithm)
1148+
GR3.setlightparameters(ambient, diffuse, specular, specular_power)
11441149
draw_axes(kind, 2)
11451150
kvs[:zrange] = [dmin, dmax]
11461151
colorbar(0.05)
@@ -1571,46 +1576,88 @@ def polarhistogram(x, kv = {})
15711576
plt.plot_data
15721577
end
15731578

1579+
# (Plot) Draw a heatmap.
15741580
# (Plot) Draw a heatmap.
15751581
def heatmap(*args)
1576-
# FIXME
1577-
args, kv = format_xyzc(*args)
1578-
_x, _y, z = args
1579-
ysize, xsize = z.shape
1580-
z = z.reshape(xsize, ysize)
1582+
kv = args.last.is_a?(Hash) ? args.pop : {}
1583+
if args.length == 1
1584+
z = args[0]
1585+
z = Numo::DFloat.cast(z) if z.is_a?(Array)
1586+
ysize, xsize = z.shape
1587+
z = z.reshape(xsize, ysize)
1588+
x = (1..xsize).to_a
1589+
y = (1..ysize).to_a
1590+
elsif args.length == 3
1591+
x, y, z = args
1592+
z = Numo::DFloat.cast(z) if z.is_a?(Array)
1593+
else
1594+
raise ArgumentError
1595+
end
15811596
create_plot(:heatmap, kv) do |plt|
1582-
plt.kvs[:xlim] ||= [0.5, xsize + 0.5]
1583-
plt.kvs[:ylim] ||= [0.5, ysize + 0.5]
1584-
plt.args = [[(1..xsize).to_a, (1..ysize).to_a, z, nil, '']]
1597+
plt.args = [[x, y, z, nil, '']]
1598+
end
1599+
end
1600+
1601+
# (Plot) Draw a nonuniformheatmap.
1602+
def nonuniformheatmap(*args)
1603+
kv = args.last.is_a?(Hash) ? args.pop : {}
1604+
if args.length == 1
1605+
z = args[0]
1606+
z = Numo::DFloat.cast(z) if z.is_a?(Array)
1607+
ysize, xsize = z.shape
1608+
z = z.reshape(xsize, ysize)
1609+
x = (1..xsize).to_a
1610+
y = (1..ysize).to_a
1611+
elsif args.length == 3
1612+
x, y, z = args
1613+
z = Numo::DFloat.cast(z) if z.is_a?(Array)
1614+
else
1615+
raise ArgumentError
1616+
end
1617+
create_plot(:nonuniformheatmap, kv) do |plt|
1618+
plt.args = [[x, y, z, nil, '']]
15851619
end
15861620
end
15871621

15881622
# (Plot) Draw a polarheatmap.
15891623
def polarheatmap(*args)
1590-
d = args.shift
1591-
# FIXME
1592-
z = Numo::DFloat.cast(d)
1593-
raise 'expected 2-D array' unless z.ndim == 2
1594-
1595-
create_plot(:polarheatmap, z, *args) do |plt|
1596-
width, height = z.shape
1597-
plt.kvs[:xlim] ||= [0.5, width + 0.5]
1598-
plt.kvs[:ylim] ||= [0.5, height + 0.5]
1599-
plt.args = [[(1..width).to_a, (1..height).to_a, z, nil, '']]
1624+
kv = args.last.is_a?(Hash) ? args.pop : {}
1625+
if args.length == 1
1626+
z = args[0]
1627+
z = Numo::DFloat.cast(z) if z.is_a?(Array)
1628+
ysize, xsize = z.shape
1629+
z = z.reshape(xsize, ysize)
1630+
x = (1..xsize).to_a
1631+
y = (1..ysize).to_a
1632+
elsif args.length == 3
1633+
x, y, z = args
1634+
z = Numo::DFloat.cast(z) if z.is_a?(Array)
1635+
else
1636+
raise ArgumentError
1637+
end
1638+
create_plot(:polarheatmap, kv) do |plt|
1639+
plt.args = [[x, y, z, nil, '']]
16001640
end
16011641
end
16021642

16031643
# (Plot) Draw a nonuniformpolarheatmap.
16041644
def nonuniformpolarheatmap(*args)
1605-
# FIXME
1606-
args, kv = format_xyzc(*args)
1607-
_x, _y, z = args
1608-
ysize, xsize = z.shape
1609-
z = z.reshape(xsize, ysize)
1645+
kv = args.last.is_a?(Hash) ? args.pop : {}
1646+
if args.length == 1
1647+
z = args[0]
1648+
z = Numo::DFloat.cast(z) if z.is_a?(Array)
1649+
ysize, xsize = z.shape
1650+
z = z.reshape(xsize, ysize)
1651+
x = (1..xsize).to_a
1652+
y = (1..ysize).to_a
1653+
elsif args.length == 3
1654+
x, y, z = args
1655+
z = Numo::DFloat.cast(z) if z.is_a?(Array)
1656+
else
1657+
raise ArgumentError
1658+
end
16101659
create_plot(:nonuniformpolarheatmap, kv) do |plt|
1611-
plt.kvs[:xlim] ||= [0.5, xsize + 0.5]
1612-
plt.kvs[:ylim] ||= [0.5, ysize + 0.5]
1613-
plt.args = [[(1..xsize).to_a, (1..ysize).to_a, z, nil, '']]
1660+
plt.args = [[x, y, z, nil, '']]
16141661
end
16151662
end
16161663

@@ -1711,15 +1758,10 @@ def barplot(*args)
17111758

17121759
# (Plot) Draw a histogram.
17131760
def histogram(series, kv = {})
1714-
horizontal = kv.delete(:horizontal)
17151761
create_plot(:hist, series, kv) do |plt|
17161762
nbins = plt.kvs[:nbins] || 0
17171763
x, y = hist(series, nbins)
1718-
plt.args = if horizontal
1719-
[[y, x, nil, nil, '']]
1720-
else
1721-
[[x, y, nil, nil, '']]
1722-
end
1764+
plt.args = [[x, y, nil, nil, '']]
17231765
end
17241766
end
17251767

0 commit comments

Comments
 (0)