gnuplotで区間を指定して横線を描きたい
step(x,from,to,y)=( (from <= x) && (x <= to) ) ? y : 0/0 # 5≦x≦10のあいだだけ、y=7の横線を描く plot step(x, 5, 10, 7)
以上。
あそんでみる
こんな感じのスクリプト
#!/bin/env ruby height = 50 length = 3 str = <<_EOT_ step(x, from, to, y) = ( (from <= x) && (x <= to) ) ? y : 0/0 height = #{height} length = #{length} set xrange [0:height+length+1] set yrange [0:height+1] set sample 5000 # set term png # set output "out.png" _EOT_ str << "plot x+10*sin(x), -x+10*cos(x)+height, " height.times do |i| rnd_length = length*rand() str << "step(x, #{i}, #{i+rnd_length}, #{i}) notitle," end puts str.chomp(",")
を書いて
$ ruby step.rb | gnuplot