Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions examples/3d_surface_plot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require "gnuplot"

Gnuplot.open do |gp|
Gnuplot::SPlot.new( gp ) do |plot|
plot.grid

plot.data = [
Gnuplot::DataSet.new( "x**2+y**2" ) do |ds|
ds.with = "pm3d"
end
]
end
end
26 changes: 12 additions & 14 deletions lib/gnuplot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ def initialize (io = nil, cmd = "plot")
@arbitrary_lines = []
@data = []
yield self if block_given?
puts "writing this to gnuplot:\n" + to_gplot + "\n" if $VERBOSE
io << to_gplot if io
puts "writing this to gnuplot:\n" + to_gplot + "\n" if $VERBOSE

if io
io << to_gplot
io << store_datasets
end
end
attr_accessor :arbitrary_lines

Expand Down Expand Up @@ -137,14 +141,18 @@ def to_gplot (io = "")
@sets.each { |var, val| io << "set #{var} #{val}\n" }
@arbitrary_lines.each{|line| io << line << "\n" }

if @data.size > 0 then
io
end

def store_datasets (io = "")
if @data.size > 0
io << @cmd << " " << @data.collect { |e| e.plot_args }.join(", ")
io << "\n"

v = @data.collect { |ds| ds.to_gplot }
io << v.compact.join("e\n")
end

io
end
end
Expand All @@ -158,16 +166,6 @@ def initialize (io = nil, cmd = "splot")
def to_gplot (io = "")
@sets.each { |var, val| io << "set #{var} #{val}\n" }

if @data.size > 0 then
io << @cmd << " "
io << @data.collect { |e| e.plot_args }.join(", ")
io << "\n"

@data.each do |ds|
io << ds.to_gsplot << "e\n"
end
end

io
end

Expand Down