In [1]:
require 'gnuplotrb'
include GnuplotRB
include Math
double_pi = PI * 2
plot3d = Splot.new(
'cos(x)*cos(y)',
xrange: -double_pi..double_pi,
yrange: -double_pi..double_pi,
style: 'function linespoints',
hidden3d: true,
isosample: 30,
term: ['pngcairo', size: [600, 600]]
)
Out[1]:
In [2]:
def z_function(x, y)
arg = x ** 2 + y ** 2
cos(arg) * exp(-arg/5.0)
end
initial = (-PI..PI).step(0.05).to_a
x = initial * initial.size
y = initial.map { |el| [el] * initial.size }.flatten
z = x.map.with_index { |val, index| z_function(val, y[index]) }
plot3d_points = Splot.new(
[[x,y,z], title: 'Surface from points'],
dgrid3d: [100, qnorm: 8],
style: 'data lines',
hidden3d: true,
xrange: -PI..PI,
yrange: -PI..PI,
term: ['pngcairo', size: [600, 600]]
)
Out[2]: