lib/annlat/plot.rb
# points is an array of values to plot on the number line
points is an array of values to plot on the number line
points is an array of values to plot on the number line
def plot(points = [])
    Gnuplot.open do |gp|
      Gnuplot::Plot.new(gp) do |plot|
        plot.terminal "pngcairo size 460,460"
        plot.output @parameters[:fn]
        plot.key "off"
        x = []
        y = []
        points << (@parameters[:high]-@parameters[:low])*2+@parameters[:high] if points.empty?
        @arrows ||= []
        if @parameters[:horizontal]
          plot.xrange "[#{@parameters[:low]}:#{@parameters[:high]}]"
          plot.yrange "[0:1]"
          plot.border 1
          plot.xtics generate_tics
          plot.unset "ytics"
          points.each do |p|
            x << p
            y << 0
          end
          @arrows.each do |a|
            if a[3]
              plot.arrow "from #{a[0]}, 0.05 to #{a[1]}, 0.05 filled lc rgb '#{a[2]}'"
            else
              plot.arrow "from #{a[0]}, 0.05 to #{a[1]}, 0.05 heads filled lc rgb '#{a[2]}'"
            end
          end
        else
          plot.yzeroaxis "lt -1"
          plot.xrange "[-1:1]"
          plot.yrange "[#{@parameters[:low]}:#{@parameters[:high]}]"
          plot.border 0
          plot.ytics "axis #{generate_tics}"
          plot.unset "xtics"
          points.each do |p|
            x << 0
            y << p
          end
          @arrows.each do |a|
            if a[3]
              plot.arrow "from 0.1, #{a[0]} to 0.1, #{a[1]} filled lc rgb '#{a[2]}'"
            else
              plot.arrow "from 0.1, #{a[0]} to 0.1, #{a[1]} heads filled lc rgb '#{a[2]}'"
            end
          end
        end
        plot.data << Gnuplot::DataSet.new([x, y]) do |ds|
          ds.with = "points pt 7 lc rgb '#{color}'"
          ds.notitle
        end
      end
    end
    if @parameters[:horizontal]
      `convert #{@parameters[:fn]} -crop 460x100+0+360 +repage #{@parameters[:fn]}`
    else
      `convert #{@parameters[:fn]} -crop 100x460+180+0 +repage #{@parameters[:fn]}`
    end
    self
  end
def plot ( points = [ ] ) Gnuplot . open do | gp | Gnuplot :: Plot . new ( gp ) do | plot | plot . terminal "pngcairo size 460,460" plot . output @parameters [ :fn ] plot . key "off" x = [ ] y = [ ] points << ( @parameters [ :high ] - @parameters [ :low ] ) * 2 + @parameters [ :high ] if points . empty? @arrows ||= [ ] if @parameters [ :horizontal ] plot . xrange "[#{@parameters[:low]}:#{@parameters[:high]}]" plot . yrange "[0:1]" plot . border 1 plot . xtics generate_tics plot . unset "ytics" points . each do | p | x << p y << 0 end @arrows . each do | a | if a [ 3 ] plot . arrow "from #{a[0]}, 0.05 to #{a[1]}, 0.05 filled lc rgb '#{a[2]}'" else plot . arrow "from #{a[0]}, 0.05 to #{a[1]}, 0.05 heads filled lc rgb '#{a[2]}'" end end else plot . yzeroaxis "lt -1" plot . xrange "[-1:1]" plot . yrange "[#{@parameters[:low]}:#{@parameters[:high]}]" plot . border 0 plot . ytics "axis #{generate_tics}" plot . unset "xtics" points . each do | p | x << 0 y << p end @arrows . each do | a | if a [ 3 ] plot . arrow "from 0.1, #{a[0]} to 0.1, #{a[1]} filled lc rgb '#{a[2]}'" else plot . arrow "from 0.1, #{a[0]} to 0.1, #{a[1]} heads filled lc rgb '#{a[2]}'" end end end plot . data << Gnuplot :: DataSet . new ( [ x , y ] ) do | ds | ds . with = "points pt 7 lc rgb '#{color}'" ds . notitle end end end if @parameters [ :horizontal ] ` convert  #{ @parameters [ :fn ] }  -crop 460x100+0+360 +repage  #{ @parameters [ :fn ] } ` else ` convert  #{ @parameters [ :fn ] }  -crop 100x460+180+0 +repage  #{ @parameters [ :fn ] } ` end self end
points is an array of values to plot on the number line
points is an array of values to plot on the number line
points