Class: CA::Gnuplot
- Inherits:
-
Object
- Object
- CA::Gnuplot
- Defined in:
- lib/carray/graphics/gnuplot.rb,
lib/carray/graphics/gnuplot.rb
Overview
:nodoc:
Defined Under Namespace
Modules: Palette Classes: ColorPalette, DataBlock, Option
Constant Summary collapse
- TMPDIR =
"."
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#last ⇒ Object
readonly
Returns the value of attribute last.
-
#multiplot_mode ⇒ Object
readonly
Returns the value of attribute multiplot_mode.
-
#multiplot_option ⇒ Object
readonly
Returns the value of attribute multiplot_option.
-
#script_mode ⇒ Object
Returns the value of attribute script_mode.
Instance Method Summary collapse
- #__guide__ ⇒ Object
- #bgcolor(spec) ⇒ Object (also: #bg_color)
-
#blank(*argv, &block) ⇒ Object
with csv file [“foo.csv”,“1:2”,“title”,“with”,“y2”].
- #canvas(*argv, &block) ⇒ Object
- #close ⇒ Object
- #color_scheme(*names) ⇒ Object
- #color_style(fgcolor, bgcolor = nil, framecolor = nil, shadowcolor = nil) ⇒ Object
- #csv(*args) ⇒ Object
- #datablock(*args) ⇒ Object
- #debug_off ⇒ Object
- #debug_on ⇒ Object
- #evaluate(expr) ⇒ Object
- #fgcolor(spec) ⇒ Object (also: #fg_color)
-
#fit(expr, params, data, opt = {}) ⇒ Object
fit(function, params, data, options).
- #framecolor(spec) ⇒ Object (also: #frame_color)
- #guide_with_wxt(*arg) ⇒ Object
- #guide_with_x11(*arg) ⇒ Object
- #image(*argv, &block) ⇒ Object
- #imagemap(*argv, &block) ⇒ Object
- #init(&block) ⇒ Object
-
#initialize(command = "gnuplot", stdout: STDOUT, timezone: "", &block) ⇒ Gnuplot
constructor
A new instance of Gnuplot.
- #multiplot(option = {}) ⇒ Object
- #output(text) ⇒ Object
- #palette(kind, *argv) ⇒ Object
- #pause(arg = -1)) ⇒ Object
- #pause_keypress ⇒ Object
- #pause_mode(arg = nil) ⇒ Object
- #pause_mouse ⇒ Object
- #pi2arc(th0, th1) ⇒ Object
-
#plot(*argv, &block) ⇒ Object
(also: #scatter, #plot2d)
with csv file [“foo.csv”,“1:2”,“title”,“with”,“axes”].
- #plot_number ⇒ Object
- #put(*args) ⇒ Object
- #reset ⇒ Object
- #reset_mode(arg = nil) ⇒ Object
- #reset_script ⇒ Object
- #scanvas(*argv, &block) ⇒ Object
- #set(*argv) ⇒ Object
-
#set_palette_discrete(data, my_palette, option = {}) ⇒ Object
my_palette = [[0, ‘#ffffff’], [1, ‘#909090’], [5, ‘#000090’], [10, ‘#000fff’], [25, ‘#0090ff’], [50, ‘#0fffee’], [75, ‘#90ff70’], [100,‘#ffee00’], [200,‘#ff7000’], [300,‘#ee0000’], [400,‘#7f0000’]] index = gp.set_palette_discrete(depth, my_palette).
- #set_xtics_monthly(start, last, fmt = nil, interval = nil, linewidth = 1, style = "lc rgb 'black' back") ⇒ Object
- #shadowcolor(spec) ⇒ Object (also: #shadow_color)
- #splot(*argv, &block) ⇒ Object (also: #scatter3d, #mesh3d, #grid3d)
- #terminal(text) ⇒ Object
- #time(data, timezone = nil) ⇒ Object
- #unset(*argv) ⇒ Object
- #xtics_histogram(ticslabels) ⇒ Object
Constructor Details
#initialize(command = "gnuplot", stdout: STDOUT, timezone: "", &block) ⇒ Gnuplot
Returns a new instance of Gnuplot.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/carray/graphics/gnuplot.rb', line 31 def initialize (command = "gnuplot", stdout: STDOUT, timezone: "", &block) begin @io, @stdout, @stderr = Open3.popen3(command + " -noraise") rescue NotImplementedError raise NotImplementedError, "system dosen't support Open3.popen3" end @defaults = {} @temp_file_count = 0 @multiplot_mode = false @script_mode = false @pause_mode = :default @reset_mode = :default @init = nil @last = nil @listen = Thread.start { Thread.abort_on_exception = true begin stdout << @stdout.gets while line = @stdout.gets ### read(1024) # unless line =~ /\Agnuplot>/ stdout << line stdout.flush # end end rescue IOError ### @stdout may externally closed end } @gnuplot_version = evaluate("GPVAL_VERSION").to_f epoch = evaluate %{strftime("%Y-%m-%d %H:%M:%S #{timezone}",0)} @EP_T = Time.parse(epoch) @EP_D = Date.parse(epoch) @EP_DT = DateTime.parse(epoch) @reset_script = reset_script() ## RESET_SCRIPT reset if block_given? begin case block.arity when 1 yield(self) when -1, 0 instance_exec(&block) else raise "invalid # of block parameters" end ensure self.close end end end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
86 87 88 |
# File 'lib/carray/graphics/gnuplot.rb', line 86 def debug @debug end |
#last ⇒ Object (readonly)
Returns the value of attribute last.
87 88 89 |
# File 'lib/carray/graphics/gnuplot.rb', line 87 def last @last end |
#multiplot_mode ⇒ Object (readonly)
Returns the value of attribute multiplot_mode.
87 88 89 |
# File 'lib/carray/graphics/gnuplot.rb', line 87 def multiplot_mode @multiplot_mode end |
#multiplot_option ⇒ Object (readonly)
Returns the value of attribute multiplot_option.
87 88 89 |
# File 'lib/carray/graphics/gnuplot.rb', line 87 def multiplot_option @multiplot_option end |
#script_mode ⇒ Object
Returns the value of attribute script_mode.
86 87 88 |
# File 'lib/carray/graphics/gnuplot.rb', line 86 def script_mode @script_mode end |
Instance Method Details
#__guide__ ⇒ Object
2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 |
# File 'lib/carray/graphics/gnuplot.rb', line 2008 def __guide__ guides = [] @pause_mouse_mode.each do |mode| guide = "" if mode.to_s[-1,1] == "!" confirm = true mode = mode.to_s[0..-2].intern else confirm = false end loop do begin put %{ set term push set term #{@pause_mouse_term} replot } case mode when :click puts "Wait mouse: 1-mouse click required" put "pause mouse" mx = evaluate "MOUSE_X" my = evaluate "MOUSE_Y" when :point puts "Draw point: 1-mouse click required" put "pause mouse" mx = evaluate "MOUSE_X" my = evaluate "MOUSE_Y" guide = %{set %{ label "" at #{mx},#{my} point }} set %{ label "" at #{mx},#{my} point pt 7 ps 2 } put %{ refresh } when :label, :clabel, :llabel, :rlabel puts "Draw label: 1-mouse click required" put "pause mouse" mx = evaluate "MOUSE_X" my = evaluate "MOUSE_Y" print "label text: " STDOUT.flush text = STDIN.gets.chomp case mode when :label, :llabel just = "left" when :clabel just = "center" when :rlabel just = "right" end guide = %{set %{ label #{text.dump} at #{"%.5g" % mx},#{"%.5g" %my} #{just} }} set %{ label #{text.dump} at #{mx},#{my} #{just} } put %{ refresh } when :arrow puts "Draw arrow: finish with right click" guide = "" pairs = [] i = 0 loop do put "pause mouse" mx = evaluate "MOUSE_X" my = evaluate "MOUSE_Y" mb = evaluate "MOUSE_BUTTON" pairs << [mx, my] if i >= 1 if i == 1 head = "" else head = "nohead" end mx1,my1 = pairs[i-1] mx2,my2 = pairs[i] guide << %{set %{ arrow from #{"%.5g" % mx2},#{"%.5g" % my2} to #{"%.5g" % mx1},#{"%.5g" % my1} #{head}} } << "\n" set %{ arrow from #{"%.5g" % mx2},#{"%.5g" % my2} to #{"%.5g" % mx1},#{"%.5g" % my1} #{head}} put %{ refresh } end if mb == "3" break end i += 1 end when :key puts "Draw key: 1-mouse click required" put "pause mouse" mx = evaluate "MOUSE_X" my = evaluate "MOUSE_Y" guide = %{set %{ key at #{"%.5g" % mx},#{"%.5g" % my} }} set %{ key at #{mx},#{my} } put %{ refresh } else raise "invalid pause_mouse_mode #{@pause_mouse_mode}" end terminal %{ pop } if @output output @output end put %{ replot } unset %{ output } if confirm print "ok? (Y/n) " STDOUT.flush begin curstty = %x{stty -g} system "stty raw -echo -icanon isig" c = STDIN.getc; ensure system "stty #{curstty}" end puts if c == ?N or c == ?n raise end end break rescue retry end end guides << guide end @pause_mouse_mode = nil puts guides.join("\n") pause end |
#bgcolor(spec) ⇒ Object Also known as: bg_color
228 229 230 231 |
# File 'lib/carray/graphics/gnuplot.rb', line 228 def bgcolor (spec) @defaults[:bgcolor] = spec put %{ bgcolor = "#{spec}" } end |
#blank(*argv, &block) ⇒ Object
with csv file
["foo.csv","1:2","title","with","y2"]
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 |
# File 'lib/carray/graphics/gnuplot.rb', line 691 def blank (*argv, &block) plots, opt = parse_args(argv, &block) put %{ unset xtics unset ytics unset x2tics unset y2tics unset xlabel unset ylabel unset x2label unset y2label unset border unset key unset grid } opt.set(:margin, :title, :bgcolor, :parametric, :options) put %{ plot [0:1] [0:1] "-" with dots -1,-1 e } if @multiplot_mode @multiplot_plot_number += 1 end pause() unless opt[:nopause] reset() unless opt[:noreset] end |
#canvas(*argv, &block) ⇒ Object
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 |
# File 'lib/carray/graphics/gnuplot.rb', line 627 def canvas (*argv, &block) plots, opt = parse_args(argv, &block) put %{ unset xtics unset x2tics unset ytics unset y2tics unset xlabel unset ylabel unset x2label unset y2label unset key } opt.set(:margin, :title, :bgcolor, :xaxis, :yaxis, :x2axis, :y2axis, :border, :parametric, :options) put %{ plot "-" with dots -1e30,-1e30 e } if @multiplot_mode @multiplot_plot_number += 1 end pause() unless opt[:nopause] reset() unless opt[:noreset] end |
#close ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/carray/graphics/gnuplot.rb', line 89 def close put("quit") @io.close @listen.join @stdout.close @stderr.close end |
#color_scheme(*names) ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/carray/graphics/gnuplot.rb', line 242 def color_scheme (*names) if @gnuplot_version >= 5.0 case names.first when :keynote put %{ set linetype 1 lc rgb "#BB2C2F" set linetype 2 lc rgb "#5E9648" set linetype 3 lc rgb "#2E578B" set linetype 4 lc rgb "#6F3B77" set linetype 5 lc rgb "#002C63" set linetype 6 lc rgb "#E6A03D" set linetype 7 lc rgb "#7D807E" set linetype 8 lc rgb "#1B0C00" set linetype cycle 8 } when :grads put %{ set linetype 2 lc rgb "#fa3c3c" set linetype 3 lc rgb "#00dc00" set linetype 4 lc rgb "#1e3cff" set linetype 5 lc rgb "#00c8c8" set linetype 6 lc rgb "#f00082" set linetype 7 lc rgb "#e6dc32" set linetype 8 lc rgb "#f08228" set linetype 9 lc rgb "#a000c8" set linetype 10 lc rgb "#a0e632" set linetype 11 lc rgb "#00a0ff" set linetype 12 lc rgb "#e6af2d" set linetype 13 lc rgb "#00d28c" set linetype 14 lc rgb "#8200dc" set linetype 15 lc rgb "#aaaaaa" set linetype cycle 15 } when :podo set %{ colorsequence podo } when :classic set %{ colorsequence classic } when :default set %{ colorsequence default } else style = [] names.each_with_index do |col, i| style << %{ set linetype #{i+1} lc rgb "#{col.to_s}"} end put style.join("\n") end else case names.first when :keynote put %{ set style increment user set style line 1 lc rgb "#BB2C2F" set style line 2 lc rgb "#5E9648" set style line 3 lc rgb "#2E578B" set style line 4 lc rgb "#6F3B77" set style line 5 lc rgb "#002C63" set style line 6 lc rgb "#E6A03D" set style line 7 lc rgb "#7D807E" set style line 8 lc rgb "#1B0C00" } when :grads put %{ set style increment user set style line 2 lc rgb "#fa3c3c" set style line 3 lc rgb "#00dc00" set style line 4 lc rgb "#1e3cff" set style line 5 lc rgb "#00c8c8" set style line 6 lc rgb "#f00082" set style line 7 lc rgb "#e6dc32" set style line 8 lc rgb "#f08228" set style line 9 lc rgb "#a000c8" set style line 10 lc rgb "#a0e632" set style line 11 lc rgb "#00a0ff" set style line 12 lc rgb "#e6af2d" set style line 13 lc rgb "#00d28c" set style line 14 lc rgb "#8200dc" set style line 15 lc rgb "#aaaaaa" } else style = ["set style increment user"] names.each_with_index do |col, i| style << %{ set style line #{i+1} lc rgb "#{col.to_s}"} end put style.join("\n") end end end |
#color_style(fgcolor, bgcolor = nil, framecolor = nil, shadowcolor = nil) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/carray/graphics/gnuplot.rb', line 195 def color_style (fgcolor, bgcolor = nil, framecolor = nil, shadowcolor = nil) if fgcolor @defaults[:fgcolor] = fgcolor put %{ fgcolor = "#{fgcolor}" } end if bgcolor @defaults[:bgcolor] = bgcolor put %{ bgcolor = "#{bgcolor}" } end if framecolor @defaults[:framecolor] = framecolor put %{ framecolor = "#{framecolor}" } end if shadowcolor @defaults[:shadowcolor] = shadowcolor put %{ shadowcolor = "#{shadowcolor}" } end end |
#csv(*args) ⇒ Object
475 476 477 478 479 480 481 482 483 484 485 486 |
# File 'lib/carray/graphics/gnuplot.rb', line 475 def csv (*args) list = [] args.each do |arg| case arg when Array list.push(arg.to_ca) else list.push(arg) end end return CArray.join(:object, list).to_csv end |
#datablock(*args) ⇒ Object
1413 1414 1415 |
# File 'lib/carray/graphics/gnuplot.rb', line 1413 def datablock (*args) return DataBlock.new(self, *args) end |
#debug_off ⇒ Object
173 174 175 |
# File 'lib/carray/graphics/gnuplot.rb', line 173 def debug_off self.debug = false end |
#debug_on ⇒ Object
169 170 171 |
# File 'lib/carray/graphics/gnuplot.rb', line 169 def debug_on self.debug = true end |
#evaluate(expr) ⇒ Object
191 192 193 |
# File 'lib/carray/graphics/gnuplot.rb', line 191 def evaluate (expr) return put("print #{expr}") end |
#fgcolor(spec) ⇒ Object Also known as: fg_color
235 236 237 238 |
# File 'lib/carray/graphics/gnuplot.rb', line 235 def fgcolor (spec) @defaults[:fgcolor] = spec put %{ fgcolor = "#{spec}" } end |
#fit(expr, params, data, opt = {}) ⇒ Object
fit(function, params, data, options)
with csv file
["foo.csv","1:2","title","with","axes"]
with csv string
["1,2\n2,3\n4,5","1:2","title","with","axes"]
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 |
# File 'lib/carray/graphics/gnuplot.rb', line 1120 def fit (expr, params, data, opt = {}) with_tempfile(2) { |tempfile, logfile| if data.first.is_a?(DataBlock) datablock = data.shift if datablock.is_csv? put("set datafile separator ','") end using = data.shift fitdata = [ datablock.name, using ? "using " + using : opt[:using] ? "using " + opt[:using] : "", ] elsif data.first.is_a?(String) file = data.shift if file =~ /,/ or file =~ /[\n\r]/ if file =~ /,/ put("set datafile separator ','") end open(tempfile, "w") { |io| io.write file } file = tempfile else unless File.exist?(file) raise "can't open file #{file} for plot2d" end end using = data.shift fitdata = [ "'#{file}'", using ? "using " + using : opt[:using] ? "using " + opt[:using] : "", ] else arg = data.map{|x| CArray.wrap_readonly(x, CA_DOUBLE) } if arg[2] and arg[2].rank == 2 and ( arg[2].size != arg[0].size or arg[2].size != arg[1].size ) xlen = arg[0].size ylen = arg[1].size arg[0] = arg[0][ylen,:%] arg[1] = arg[1][:%,xlen] record = arg[0].dim1 elsif arg[0] and arg[0].rank == 2 record = arg[0].dim1 else record = arg[0].dim0 end datalen = arg.size out = CArray.merge(CA_DOUBLE, arg, -1) open(tempfile, "w") { |io| out.unmask_copy(0.0/0.0).dump_binary(io) } fitdata = [ "'#{tempfile}'", "binary", record ? "record=#{record}" : "", "format='#{'%double'*datalen}'", "using " + ( opt[:using] || "#{(1..datalen).map{|x|'($%i)' % x}.join(':')}" ), ] end if opt[:ranges] ranges = opt[:ranges] else ranges = "" end set("fit logfile '#{logfile}' errorvariables covariancevariables") put("fit #{ranges} #{expr} #{fitdata.join(" ")} via " + params.map{|x| x.to_s}.join(",")) res = OpenStruct.new res.expression = expr res.parameters = params result_params = put("print " + params.map{|x| x.to_s}.join(",")).split.map{|_x| _x.to_f} result_err = put("print " + params.map{|x| x.to_s + "_err"}.join(",")).split.map{|_x| _x.to_f} result_cov = put("print " + params.map{|x| params.map{|y| "FIT_COV_" + x.to_s + "_" + y.to_s }}.join(",")).split.map{|_x| _x.to_f} params.each_with_index do |name, i| res.send(name.to_s+"=", result_params[i]) res.send(name.to_s+"_err=", result_err[i]) end i=0 params.each do |x| params.each do |y| res.send("cov_" + x.to_s + "_" + y.to_s + "=", result_cov[i]) end i+=1 end res.log = File.read(logfile) result = put("print FIT_NDF, FIT_WSSR, FIT_STDFIT, FIT_P") res.ndf, res.wssr, res.stdfit, res.fit_p = result.split.map{|_x| _x.to_f} return result_params, res } end |
#framecolor(spec) ⇒ Object Also known as: frame_color
214 215 216 217 |
# File 'lib/carray/graphics/gnuplot.rb', line 214 def framecolor (spec) @defaults[:framecolor] = spec put %{ framecolor = "#{spec}" } end |
#guide_with_wxt(*arg) ⇒ Object
2002 2003 2004 2005 2006 |
# File 'lib/carray/graphics/gnuplot.rb', line 2002 def guide_with_wxt (*arg) @pause_mouse_mode = arg @pause_mouse_term = "wxt" __guide__ end |
#guide_with_x11(*arg) ⇒ Object
1996 1997 1998 1999 2000 |
# File 'lib/carray/graphics/gnuplot.rb', line 1996 def guide_with_x11 (*arg) @pause_mouse_mode = arg @pause_mouse_term = "x11" __guide__ end |
#image(*argv, &block) ⇒ Object
1102 1103 1104 |
# File 'lib/carray/graphics/gnuplot.rb', line 1102 def image (*argv, &block) raise "image() will be obsolete, use plot(..., :with=>'(rgb)image')" end |
#imagemap(*argv, &block) ⇒ Object
1106 1107 1108 |
# File 'lib/carray/graphics/gnuplot.rb', line 1106 def imagemap (*argv, &block) raise "imagemap() will be obsolete, use plot(..., :with=>'(rgb)image')" end |
#init(&block) ⇒ Object
177 178 179 180 181 |
# File 'lib/carray/graphics/gnuplot.rb', line 177 def init (&block) @init = block @init.call return @init end |
#multiplot(option = {}) ⇒ Object
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 |
# File 'lib/carray/graphics/gnuplot.rb', line 582 def multiplot (option = {}) @multiplot_mode = true @multiplot_option = option @multiplot_plot_number = 1 @saved_init = @init = "" if option[:layout] << " layout " + option[:layout].join(",") if option[:columnsfirst] << " columnsfirst " else << " rowsfirst " end if option[:upwards] << " upwards " else << " downwards " end end if option[:scale] << " scale " + option[:scale].join(",") end if option[:offset] << " offset " + option[:offset].join(",") end if option[:title] << " title '" + option[:title] + "'" end put( "set multiplot" + ) reset() yield ensure put( "unset multiplot" ) @multiplot_option = nil @multiplot_mode = false @multiplot_plot_number = 0 @init = @saved_init unless option[:nopause] pause end unless option[:noreset] reset end end |
#output(text) ⇒ Object
425 426 427 428 429 |
# File 'lib/carray/graphics/gnuplot.rb', line 425 def output (text) @output = text text = text.split("\n").map{|l| l.strip }.join(" ").strip put("set output '#{text}'") end |
#palette(kind, *argv) ⇒ Object
1676 1677 1678 |
# File 'lib/carray/graphics/gnuplot.rb', line 1676 def palette (kind, *argv) return Palette.set(self, kind, *argv) end |
#pause(arg = -1)) ⇒ Object
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'lib/carray/graphics/gnuplot.rb', line 351 def pause (arg = -1) if @multiplot_mode return else case @pause_mode when :none return when :mouse pause_mouse when :keypress pause_keypress else # :key term = evaluate("GPVAL_TERM") case term when /x11/, /aqua/, /wxt/ STDIN.gets end end end end |
#pause_keypress ⇒ Object
380 381 382 383 384 385 386 |
# File 'lib/carray/graphics/gnuplot.rb', line 380 def pause_keypress put "pause mouse keypress" mx = evaluate "MOUSE_X" my = evaluate "MOUSE_Y" mk = evaluate "MOUSE_KEY" return [mx, my, mk] end |
#pause_mode(arg = nil) ⇒ Object
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
# File 'lib/carray/graphics/gnuplot.rb', line 331 def pause_mode (arg = nil) # :none - no pausing # :default - return on terminal # :mouse - mouse click on window # :keypress - keypress on window orig = @pause_mode if arg @pause_mode = arg else @pause_mode = :default end if block_given? begin yield ensure @pause_mode = orig end end end |
#pause_mouse ⇒ Object
372 373 374 375 376 377 378 |
# File 'lib/carray/graphics/gnuplot.rb', line 372 def pause_mouse put "pause mouse" mx = evaluate "MOUSE_X" my = evaluate "MOUSE_Y" mk = evaluate "MOUSE_KEY" return [mx, my, mk] end |
#pi2arc(th0, th1) ⇒ Object
1986 1987 1988 |
# File 'lib/carray/graphics/gnuplot.rb', line 1986 def pi2arc (th0, th1) return format("%f:%f", -th1+90, -th0+90) end |
#plot(*argv, &block) ⇒ Object Also known as: scatter, plot2d
with csv file
["foo.csv","1:2","title","with","axes"]
with csv string
["1,2\n2,3\n4,5","1:2","title","with","axes"]
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 |
# File 'lib/carray/graphics/gnuplot.rb', line 728 def plot (*argv, &block) @init.call if @init plots, opt = parse_args(argv, &block) @last = plots + [opt] with_tempfile(plots.size) { |*tempfile| plot_list = [] plots.each_with_index do |arg, i| arg = arg.clone local_ranges = [] loop do case arg.first when Range rng = arg.shift local_ranges << "[" + [rng.begin,rng.end].join(":") + "] " when Hash var,rng = arg.shift.first case var when :x local_ranges[0] = "[" + [rng.begin,rng.end].join(":") + "] " when :y local_ranges[1] = "[" + [rng.begin,rng.end].join(":") + "] " when :z local_ranges[2] = "[" + [rng.begin,rng.end].join(":") + "] " else local_ranges << "[#{var}=" + [rng.begin,rng.end].join(":") + "] " end else break end end if i == 0 and not local_ranges.empty? local_ranges.unshift "sample" end local_ranges = local_ranges.map{|v| v.nil? ? "[:]" : v } if arg.first.is_a?(Symbol) and arg.first == :newhistogram arg.shift arg, dataspec, using, title, with, axis = *parse_data(arg) plot_cmd = [ "newhistogram", using ? using : "", title ? title : "", with ? with : "", ] elsif arg.first.is_a?(DataBlock) datablock = arg.shift if datablock.is_csv? put("set datafile separator ','") end arg, dataspec, using, title, with, axis = *parse_data(arg) plot_cmd = local_ranges + [ datablock.name, dataspec ? dataspec : "", @gnuplot_version >= 4.4 ? "volatile" : "", opt[:using] ? "using " + opt[:using] : using ? using : "", axis ? "axes #{axis}" : "", with ? "with #{with}" : opt[:with] ? "with #{opt[:with]}" : "", title ? "title #{title}" : "" ] elsif arg.first.is_a?(String) file = arg.shift if file =~ /\.(png|jpg)\z/ arg, dataspec, using, title, with, axis = *parse_data(arg) plot_cmd = local_ranges + [ "'#{file}'", dataspec ? dataspec : "", "binary filetype=auto", @gnuplot_version >= 4.4 ? "volatile" : "", opt[:using] ? "using " + opt[:using] : using ? using : "", axis ? "axes #{axis}" : "", with ? "with #{with}" : opt[:with] ? "with #{opt[:with]}" : "", title ? "title #{title}" : "" ] else if file == "" elsif file =~ /,/ or file =~ /[\n\r]/ if file =~ /,/ put("set datafile separator ','") end file = file.gsub(/UNDEF/, "NaN") open(tempfile[i], "w") { |io| io.write file } file = tempfile[i] else unless File.exist?(file) raise "can't open file #{file} for plot2d" end end arg, dataspec, using, title, with, axis = *parse_data(arg) plot_cmd = local_ranges + [ "'#{file}'", dataspec ? dataspec : "", @gnuplot_version >= 4.4 ? "volatile" : "", opt[:using] ? "using " + opt[:using] : using ? using : "", axis ? "axes #{axis}" : "", with ? "with #{with}" : opt[:with] ? "with #{opt[:with]}" : "", title ? "title #{title}" : "" ] end elsif arg.first.is_a?(Array) funcs, dataspec, using, title, with, axis = *parse_data(arg) plot_cmd = local_ranges + [ funcs.join(","), dataspec ? dataspec : "", opt[:using] ? "using " + opt[:using] : using ? using : "", axis ? "axes #{axis}" : "", with ? "with #{with}" : opt[:with] ? "with #{opt[:with]}" : "", title ? "title #{title}" : "" ] else arg, dataspec, using, title, with, axis = *parse_data(arg) arg = arg.map{|x| CArray.wrap_readonly(x, CA_DOUBLE) } if with.to_s =~ /rgbimage/ or opt[:with].to_s =~ /rgbimage/ if arg[2] and arg[2].rank >= 2 and ( arg[2].size != arg[0].size or arg[2].size != arg[1].size ) xlen = arg[0].size ylen = arg[1].size arg[0] = arg[0][ylen,:%] arg[1] = arg[1][:%,xlen] if arg[2].rank == 3 arg2 = arg[2] arg[2] = arg2[nil,nil,0] arg[3] = arg2[nil,nil,1] arg[4] = arg2[nil,nil,2] end end is_image = true is_rgb = true elsif with.to_s =~ /image/ or opt[:with].to_s =~ /image/ if arg[2] and arg[2].rank == 2 and ( arg[2].size != arg[0].size or arg[2].size != arg[1].size ) xlen = arg[0].size ylen = arg[1].size arg[0] = arg[0][ylen,:%] arg[1] = arg[1][:%,xlen] end is_image = true is_rgb = false else arg = arg.map{|x| x.rank > 1 ? x[nil] : x } is_image = false end out = CArray.merge(CA_DOUBLE, arg, -1) if is_image if is_rgb datalen = out.dim2 if arg.size == 1 datalen = 1 array = "(" + [out.dim1,out.dim0].join(',') + ")" record = nil else datalen = 5 array = nil record = "(" + [out.dim1,out.dim0].join(',') + ")" end else if arg.size == 1 datalen = 1 array = "(" + [out.dim1,out.dim0].join(',') + ")" record = nil else datalen = 3 array = nil record = out.dim1*out.dim0 end end else datalen = arg.size record = out.dim0 array = nil end open(tempfile[i], "w") { |io| out.unmask_copy(0.0/0.0).dump_binary(io) } plot_cmd = local_ranges + [ "'#{tempfile[i]}'", "binary", record ? "record=#{record}" : "", array ? "array=#{array}" : "", "format='#{'%double'*datalen}'", dataspec ? dataspec : "", @gnuplot_version >= 4.4 ? "volatile" : "", opt[:using] ? "using " + opt[:using] : using ? using : "using " + "#{(1..datalen).map{|x|'%i' % x}.join(':')}", axis ? "axes #{axis}" : "", with ? "with #{with}" : opt[:with] ? "with #{opt[:with]}" : "", title ? "title #{title}" : "" ] end plot_list.push(plot_cmd.join(" ")) end opt.set(:margin, :title, :key, :bgcolor, :palette, :timefmt, :xaxis, :x2axis, :yaxis, :y2axis, :cbaxis, :grid, :border, :parametric, :options) put("plot " + plot_list.join(",")) if @multiplot_mode @multiplot_plot_number += 1 end pause() unless opt[:nopause] reset() unless opt[:noreset] } end |
#plot_number ⇒ Object
578 579 580 |
# File 'lib/carray/graphics/gnuplot.rb', line 578 def plot_number return @multiplot_plot_number end |
#put(*args) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/carray/graphics/gnuplot.rb', line 97 def put (*args) lines = args.map {|s| s.respond_to?(:to_gnuplot) ? s.to_gnuplot : s.to_s } command = lines.join("\n") if @debug STDERR.puts command end thread = Thread.start { begin size = command.size s = 0 while s < size s += @io.write(command[s, 2048]) end @io.puts @io.puts %{ print "SIGNAL FOR CA::Gnuplot" } @io.flush rescue Errno::EPIPE end } output = "" while line = @stderr.gets case line.chomp when /SIGNAL FOR CA::Gnuplot$/ STDERR.print(output) if @debug and not output.empty? return output.chomp when / line \d+: (.*?) / if $1 =~ /warning:/ output << line STDERR.print output next else output << line STDERR.print output raise "Gnuplot Processor Error" end else output << line end end ensure thread.join end |
#reset ⇒ Object
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
# File 'lib/carray/graphics/gnuplot.rb', line 404 def reset () if @script_mode or @reset_mode == :none return end if @multiplot_mode and ( @multiplot_option[:layout] or @multiplot_option[:noreset] ) put @reset_script put("set xyplane relative 0", "set key Left reverse noautotitle") else put "reset" put("set xyplane relative 0", "set key Left reverse noautotitle") end end |
#reset_mode(arg = nil) ⇒ Object
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
# File 'lib/carray/graphics/gnuplot.rb', line 388 def reset_mode (arg = nil) orig = @reset_mode if arg @reset_mode = arg else @reset_mode = :default end if block_given? begin yield ensure @reset_mode = orig end end end |
#reset_script ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/carray/graphics/gnuplot.rb', line 140 def reset_script # TO BE COMENNTED OUT # set size ratio 0 1,1 # set origin 0,0 # set lmargin -1 # set bmargin -1 # set rmargin -1 # set tmargin -1 # set locale "ja_JP.UTF-8" # set decimalsign # set encoding # set loadpath # set fontpath # set psdir # set fit brief errorvariables nocovariancevariables errorscaling prescale nowrap script = put(%{ save set "|cat 1>&2" }).split($/) script.delete_if {|s| s =~ /^set size ratio/ } script.delete_if {|s| s =~ /^set origin/ } script.delete_if {|s| s =~ /^set .margin/ } script.delete_if {|s| s =~ /^set locale/ } script.delete_if {|s| s =~ /^set decimalsign/ } script.delete_if {|s| s =~ /^set encoding/ } script.delete_if {|s| s =~ /^set loadpath/ } script.delete_if {|s| s =~ /^set fontpath/ } script.delete_if {|s| s =~ /^set psdir/ } script.delete_if {|s| s =~ /^set fit/ } return script.join($/) end |
#scanvas(*argv, &block) ⇒ Object
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 |
# File 'lib/carray/graphics/gnuplot.rb', line 656 def scanvas (*argv, &block) plots, opt = parse_args(argv, &block) put %{ unset xtics unset x2tics unset ytics unset y2tics unset ztics unset xlabel unset ylabel unset zlabel unset x2label unset y2label unset key } opt.set(:margin, :title, :bgcolor, :xaxis, :yaxis, :zaxis, :border, :parametric, :options) put %{ splot "-" with dots -1e30,-1e30,-1e30 e } if @multiplot_mode @multiplot_plot_number += 1 end pause() unless opt[:nopause] reset() unless opt[:noreset] end |
#set(*argv) ⇒ Object
183 184 185 |
# File 'lib/carray/graphics/gnuplot.rb', line 183 def set (*argv) put "set " + argv.map{|s| s.gsub(/\n/,'') }.join(" ") end |
#set_palette_discrete(data, my_palette, option = {}) ⇒ Object
my_palette = [[0, ‘#ffffff’],
[1, '#909090'],
[5, '#000090'],
[10, '#000fff'],
[25, '#0090ff'],
[50, '#0fffee'],
[75, '#90ff70'],
[100,'#ffee00'],
[200,'#ff7000'],
[300,'#ee0000'],
[400,'#7f0000']]
index = gp.set_palette_discrete(depth, my_palette)
1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 |
# File 'lib/carray/graphics/gnuplot.rb', line 1225 def set_palette_discrete (data, my_palette, option = {}) default = { :model=>"RGB", :continuous=>false, :lower=>nil, :upper=>nil, :lower_label=>false, :upper_label=>false } option = default.update(option) model, continuous, lower, lower_label, upper, upper_label = option.values_at(:model, :continuous, :lower, :lower_label, :upper, :upper_label) levels = my_palette.size scale = my_palette.map{|r| r[0] } scalec = scale.clone color = my_palette.map{|r| r[1] } out = [] cbmin = 0 cbmax = levels - 1 maxcolors = levels-1 if continuous if lower out << [-1, %{'#{lower}'}] cbmin = -1 maxcolors += 1 end (levels).times do |i| level = i out << [level, %{'#{color[i]}'}] end if upper out << [levels, %{'#{upper}'}] cbmax = levels maxcolors += 1 end else if lower out << [-1, %{'#{lower}'}] out << [0, %{'#{lower}'}] cbmin = -1 maxcolors += 1 end (levels-1).times do |i| level = i level1 = i+1 out << [level, %{'#{color[i]}'}] out << [level1, %{'#{color[i]}'}] end if upper out << [levels-1, %{'#{upper}'}] out << [levels, %{'#{upper}'}] cbmax = levels maxcolors += 1 end end put ["set palette model #{model} maxcolors #{maxcolors} defined (\\", out.map{|list| " " + list.join(" ")}.join(",\\\n") + "\\", ")"].join("\n") out = [] if lower and lower_label out << [%{''{/Symbol <}#{scale.first}'}, cbmin] end scale.each_with_index do |s, i| out << [%{'#{s}'}, i] end if upper and upper_label out << [%{'{/Symbol \\263}#{scale.last}'}, cbmax] end put %{ set cbtics (#{out.map {|d| d.join(" ")}.join(",")}) } put %{ set cbrange [#{cbmin}:#{cbmax}] } return CA_DOUBLE(scale).section(data) end |
#set_xtics_monthly(start, last, fmt = nil, interval = nil, linewidth = 1, style = "lc rgb 'black' back") ⇒ Object
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 |
# File 'lib/carray/graphics/gnuplot.rb', line 1297 def set_xtics_monthly (start, last, fmt = nil, interval=nil, linewidth = 1, style = "lc rgb 'black' back") unless fmt fmt = "%b" end unless interval interval = 3 end case start when String start = DateTime.parse(start) end case last when String last = DateTime.parse(last) end if interval < 0 start = DateTime.parse(start.strftime("%Y-%m-01")) + 0.5 last = (DateTime.parse(last.strftime("%Y-%m-01"))) + 0.5 >> 1 else start = DateTime.parse(start.strftime("%Y-%m-01")) last = (DateTime.parse(last.strftime("%Y-%m-01"))) >> 1 end set %{ xrange [#{time(start)}:#{time(last)}] } if linewidth > 0 set %{ xtics ("" 0) scale 0,2 mirror } set %{ x2tics ("" 0) scale 0,1 mirror } else set %{ xtics ("" 0) scale 0,0 mirror } set %{ x2tics ("" 0) scale 0,0 mirror } end d = start while d <= last set %{ xtics add ('' #{time(d)} 1) } set %{ xtics add ('#{d.strftime(fmt)}' #{time(d+15)} 0) } case interval when -2,2 set %{ x2tics add ('' #{time(d+15)} 1) } when -3,3 set %{ x2tics add ('' #{time(d+10)} 1) } set %{ x2tics add ('' #{time(d+20)} 1) } when -6,6 set %{ x2tics add ('' #{time(d+5)} 1) } set %{ x2tics add ('' #{time(d+10)} 1) } set %{ x2tics add ('' #{time(d+15)} 1) } set %{ x2tics add ('' #{time(d+20)} 1) } set %{ x2tics add ('' #{time(d+25)} 1) } else end d >>= 1 end if linewidth > 0 d = start >> 1 while d < last set %{ arrow nohead from #{time(d)}, graph 0 rto graph 0, graph 1 #{style} } d >>= 1 end end end |
#shadowcolor(spec) ⇒ Object Also known as: shadow_color
221 222 223 224 |
# File 'lib/carray/graphics/gnuplot.rb', line 221 def shadowcolor (spec) @defaults[:shadowcolor] = spec put %{ shadowcolor = "#{spec}" } end |
#splot(*argv, &block) ⇒ Object Also known as: scatter3d, mesh3d, grid3d
938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 |
# File 'lib/carray/graphics/gnuplot.rb', line 938 def splot (*argv, &block) @init.call if @init plots, opt = parse_args(argv, &block) @last = plots + [opt] with_tempfile(plots.size) { |*tempfile| plot_list = [] plots.each_with_index do |arg, i| arg = arg.clone local_ranges = [] loop do case arg.first when Range rng = arg.shift local_ranges << "[" + [rng.begin,rng.end].join(":") + "] " when Hash var,rng = arg.shift.first case var when :x local_ranges[0] = "[" + [rng.begin,rng.end].join(":") + "] " when :y local_ranges[1] = "[" + [rng.begin,rng.end].join(":") + "] " when :z local_ranges[2] = "[" + [rng.begin,rng.end].join(":") + "] " else local_ranges << "[#{var}=" + [rng.begin,rng.end].join(":") + "] " end else break end end if i == 0 and not local_ranges.empty? local_ranges.unshift "sample" end local_ranges = local_ranges.map{|v| v.nil? ? "[:]" : v } if arg.first.is_a?(DataBlock) datablock = arg.shift if datablock.is_csv? put("set datafile separator ','") end arg, dataspec, using, title, with, axis = *parse_data(arg) plot_cmd = local_ranges + [ datablock.name, dataspec ? dataspec : "", @gnuplot_version >= 4.4 ? "volatile" : "", opt[:using] ? "using " + opt[:using] : using ? using : "", axis ? "axes #{axis}" : "", with ? "with #{with}" : opt[:with] ? "with #{opt[:with]}" : "", title ? "title #{title}" : "" ] elsif arg.first.is_a?(String) file = arg.shift if file =~ /\.(png|jpg)\z/ arg, dataspec, using, title, with, axis = *parse_data(arg) plot_cmd = [ "'#{file}'", dataspec ? dataspec : "", "binary filetype=auto", @gnuplot_version >= 4.4 ? "volatile" : "", opt[:using] ? "using " + opt[:using] : using ? using : "", axis ? "axes #{axis}" : "", with ? "with #{with}" : opt[:with] ? "with #{opt[:with]}" : "", title ? "title #{title}" : "" ] else if file == "" elsif file =~ /,/ or file =~ /[\n\r]/ if file =~ /,/ put("set datafile separator ','") end file = file.gsub(/UNDEF/, "NaN") open(tempfile[i], "w") { |io| io.write file } file = tempfile[i] else unless File.exist?(file) raise "can't open file #{file} for splot" end end arg, dataspec, using, title, with, axis = *parse_data(arg) plot_cmd = [ "'#{file}'", dataspec ? dataspec : "", @gnuplot_version >= 4.4 ? "volatile" : "", opt[:using] ? "using " + opt[:using] : using ? using : "", axis ? "axes #{axis}" : "", with ? "with #{with}" : opt[:with] ? "with #{opt[:with]}" : "", title ? "title #{title}" : "" ] end elsif arg.first.is_a?(Array) funcs, dataspec, using, title, with, axis = *parse_data(arg) plot_cmd = [ funcs.join(","), dataspec ? dataspec : "", opt[:using] ? "using " + opt[:using] : using ? using : "", axis ? "axes #{axis}" : "", with ? "with #{with}" : opt[:with] ? "with #{opt[:with]}" : "", title ? "title #{title}" : "" ] else arg, dataspec, using, title, with, axis = *parse_data(arg) arg = arg.map{|x| CArray.wrap_readonly(x, CA_DOUBLE) } if arg[2] and arg[2].rank == 2 and ( arg[2].size != arg[0].size or arg[2].size != arg[1].size ) xlen = arg[0].size ylen = arg[1].size arg[0] = arg[0][ylen,:%] arg[1] = arg[1][:%,xlen] is_image = true elsif arg[0] and arg[0].rank == 2 is_image = true elsif arg[0] and arg[0].rank == 3 is_image = true else is_image = false end out = CArray.merge(CA_DOUBLE, arg, -1) if is_image datalen = out.dim2 record = "(" + [out.dim1,out.dim0].join(",") + ")" else datalen = arg.size record = out.dim0 end open(tempfile[i], "w") { |io| out.unmask_copy(0.0/0.0).dump_binary(io) } plot_cmd = local_ranges + [ "'#{tempfile[i]}'", "binary", record ? "record=#{record}" : "", "format='#{'%double'*datalen}'", dataspec ? dataspec : "", @gnuplot_version >= 4.4 ? "volatile" : "", opt[:using] ? "using " + opt[:using] : using ? using : "using " + "#{(1..datalen).map{|x|'%i' % x}.join(':')}", axis ? "axes #{axis}" : "", with ? "with #{with}" : opt[:with] ? "with #{opt[:with]}" : "", title ? "title #{title}" : "" ] end plot_list.push(plot_cmd.join(" ")) end opt.set(:margin, :title, :key, :bgcolor, :view, :palette, :timefmt, :xaxis, :yaxis, :zaxis, :cbaxis, :border, :parametric, :options) put("splot " + plot_list.join(",")) if @multiplot_mode @multiplot_plot_number += 1 end pause() unless opt[:nopause] reset() unless opt[:noreset] } end |
#terminal(text) ⇒ Object
420 421 422 423 |
# File 'lib/carray/graphics/gnuplot.rb', line 420 def terminal (text) text = text.split("\n").map{|l| l.strip }.join(" ").strip put("set term #{text}") end |
#time(data, timezone = nil) ⇒ Object
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 |
# File 'lib/carray/graphics/gnuplot.rb', line 431 def time (data, timezone = nil) if timezone epoch = evaluate %{strftime("%Y-%m-%d %H:%M:%S #{timezone}",0)} ep_t = Time.parse(epoch) ep_d = Date.parse(epoch) ep_dt = DateTime.parse(epoch) else ep_t = @EP_T ep_d = @EP_D ep_dt = @EP_DT end case data when Numeric data when String Time.parse(data) - @EP_T when Time data - ep_t when Date (data - ep_d)*86400 when DateTime (data - ep_dt)*86400 when CArray return data.convert(CA_DOUBLE){|x| case x when Numeric x when Time x - ep_t when Date (x - ep_d)*86400 when DateTime (x - ep_dt)*86400 when String Time.parse(x) - ep_t end } when Range time(data.first, timezone)..time(data.last, timezone) end end |
#unset(*argv) ⇒ Object
187 188 189 |
# File 'lib/carray/graphics/gnuplot.rb', line 187 def unset (*argv) put "unset " + argv.map{|s| s.gsub(/\n/,'') }.join(" ") end |
#xtics_histogram(ticslabels) ⇒ Object
1990 1991 1992 1993 1994 |
# File 'lib/carray/graphics/gnuplot.rb', line 1990 def xtics_histogram (ticslabels) max = ticslabels.size - 1 return -0.5..max+0.5, (0..max).map{|k|[k,ticslabels[k]]} + (0..max-1).map{|k|[k+0.5,"",1]} end |