Pardon if this is spelled out somewhere, but I couldn't find documentation on how to plot disjoint line segments. As I figured out the recipe, I thought I'd share.
The trick is to insert nil values in your x-y data wherever you want to start a new segment:
# Example of plotting disjoint line segments. The
# secret is that a nil separates a segment...
require 'gnuplot'
Gnuplot.open do |gp|
Gnuplot::Plot.new( gp ) do |plot|
plot.title "segment example"
xs = [-2, 0, nil, 0, 2, nil, 2, 4]
ys = [0.6, 0.6, nil, -0.6, -0.6, nil, 0, 0.5]
plot.data << Gnuplot::DataSet.new([xs,ys]) do |ds|
ds.with = "lines"
ds.linewidth = 4
ds.notitle
end
end
end
|