Class: Numo::Gnuplot
- Inherits:
-
Object
- Object
- Numo::Gnuplot
- Defined in:
- lib/numo/gnuplot.rb
Defined Under Namespace
Classes: GnuplotError, KvItem, OptsToS, PlotData, PlotItem, SPlotArray, SPlotItem, SPlotRecord
Constant Summary collapse
- VERSION =
"0.1.3"- POOL =
[]
- DATA_FORMAT =
"%.5g"- KNOWN_EXT =
{"ps"=>"postscript","jpg"=>"jpeg"}
Instance Attribute Summary collapse
-
#gnuplot_version ⇒ Object
readonly
Returns the value of attribute gnuplot_version.
-
#history ⇒ Object
readonly
Returns the value of attribute history.
-
#last_message ⇒ Object
readonly
Returns the value of attribute last_message.
Class Method Summary collapse
Instance Method Summary collapse
-
#clear ⇒ Object
The ‘clear` command erases the current screen or output device as specified by `set output`.
-
#debug_off ⇒ Object
turn off debug.
-
#debug_on ⇒ Object
turn on debug.
-
#exit ⇒ Object
The ‘exit` and `quit` commands will exit `gnuplot`.
-
#help(s = nil) ⇒ Object
The ‘help` command displays built-in help.
-
#initialize(gnuplot_command = "gnuplot") ⇒ Gnuplot
constructor
A new instance of Gnuplot.
-
#load(filename) ⇒ Object
The ‘load` command executes each line of the specified input file.
-
#lower_plot(plot_window_nb = nil) ⇒ Object
(also: #lower)
The ‘lower` command lowers plot window(s).
-
#output(filename, *opts) ⇒ Object
output current plot to file with terminal setting from extension (not Gnuplot command).
-
#pause(*args) ⇒ Object
The ‘pause` command used to wait for events on window.
-
#plot(*args) ⇒ Object
draw 2D functions and data.
-
#quit ⇒ Object
The ‘exit` and `quit` commands will exit `gnuplot`.
-
#raise_plot(plot_window_nb = nil) ⇒ Object
(also: #raise)
The ‘raise` command raises plot window(s).
-
#refresh ⇒ Object
The ‘refresh` reformats and redraws the current plot using the data already read in.
-
#replot ⇒ Object
replot is not recommended, use refresh.
-
#reset(x = nil) ⇒ Object
The ‘reset` command causes all graph-related options that can be set with the `set` command to take on their default values.
-
#set(*args) ⇒ Object
The ‘set` command is used to set lots of options.
-
#show(x) ⇒ Object
The ‘show` command shows their settings.
-
#splot(*args) ⇒ Object
draws 2D projections of 3D surfaces and data.
-
#to_s ⇒ Object
for irb workspace name.
-
#unset(*args) ⇒ Object
The ‘unset` command is used to return to their default state.
-
#var(name) ⇒ Object
‘var` returns Gnuplot variable (not Gnuplot command).
Constructor Details
#initialize(gnuplot_command = "gnuplot") ⇒ Gnuplot
Returns a new instance of Gnuplot.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/numo/gnuplot.rb', line 24 def initialize(gnuplot_command="gnuplot") @history = [] @debug = false r0,@iow = IO.pipe @ior,w2 = IO.pipe IO.popen(gnuplot_command,:in=>r0,:err=>w2) r0.close w2.close @gnuplot_version = send_cmd("print GPVAL_VERSION")[0].chomp if /\.(\w+)$/ =~ (filename = ENV['NUMO_GNUPLOT_OUTPUT']) ext = $1 ext = KNOWN_EXT[ext] || ext opts = ENV['NUMO_GNUPLOT_OPTION'] || '' set terminal:[ext,opts] set output:filename end end |
Instance Attribute Details
#gnuplot_version ⇒ Object (readonly)
Returns the value of attribute gnuplot_version.
44 45 46 |
# File 'lib/numo/gnuplot.rb', line 44 def gnuplot_version @gnuplot_version end |
#history ⇒ Object (readonly)
Returns the value of attribute history.
42 43 44 |
# File 'lib/numo/gnuplot.rb', line 42 def history @history end |
#last_message ⇒ Object (readonly)
Returns the value of attribute last_message.
43 44 45 |
# File 'lib/numo/gnuplot.rb', line 43 def @last_message end |
Class Method Details
.default ⇒ Object
20 21 22 |
# File 'lib/numo/gnuplot.rb', line 20 def self.default POOL[0] ||= self.new end |
Instance Method Details
#clear ⇒ Object
The ‘clear` command erases the current screen or output device as specified by `set output`. This usually generates a formfeed on hardcopy devices.
153 154 155 156 |
# File 'lib/numo/gnuplot.rb', line 153 def clear send_cmd "clear" nil end |
#debug_off ⇒ Object
turn off debug
209 210 211 |
# File 'lib/numo/gnuplot.rb', line 209 def debug_off @debug = false end |
#debug_on ⇒ Object
turn on debug
204 205 206 |
# File 'lib/numo/gnuplot.rb', line 204 def debug_on @debug = true end |
#exit ⇒ Object
The ‘exit` and `quit` commands will exit `gnuplot`.
159 160 161 162 |
# File 'lib/numo/gnuplot.rb', line 159 def exit send_cmd "exit" nil end |
#help(s = nil) ⇒ Object
The ‘help` command displays built-in help.
102 103 104 |
# File 'lib/numo/gnuplot.rb', line 102 def help(s=nil) puts send_cmd "help #{s}\n\n" end |
#load(filename) ⇒ Object
The ‘load` command executes each line of the specified input file.
130 131 132 133 |
# File 'lib/numo/gnuplot.rb', line 130 def load(filename) send_cmd "load '#{filename}'" nil end |
#lower_plot(plot_window_nb = nil) ⇒ Object Also known as: lower
The ‘lower` command lowers plot window(s)
145 146 147 148 |
# File 'lib/numo/gnuplot.rb', line 145 def lower_plot(plot_window_nb=nil) send_cmd "lower #{plot_window_nb}" nil end |
#output(filename, *opts) ⇒ Object
output current plot to file with terminal setting from extension (not Gnuplot command)
190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/numo/gnuplot.rb', line 190 def output(filename,*opts) if /\.(\w+)$/ =~ filename ext = $1 ext = KNOWN_EXT[ext]||ext set terminal:[ext,*opts], output:filename refresh unset :terminal, :output else kernel_raise GnuplotError,"file extension is not given" end end |
#pause(*args) ⇒ Object
The ‘pause` command used to wait for events on window. Carriage return entry (-1 is given for argument) and text display option is disabled.
pause 10
pause 'mouse'
pause mouse:%w[keypress,button1,button2,button3,close,any]
124 125 126 127 |
# File 'lib/numo/gnuplot.rb', line 124 def pause(*args) send_cmd("pause #{OptsToS.new(*args)}").join.chomp nil end |
#plot(*args) ⇒ Object
draw 2D functions and data.
47 48 49 50 |
# File 'lib/numo/gnuplot.rb', line 47 def plot(*args) _plot_splot("plot",args) nil end |
#quit ⇒ Object
The ‘exit` and `quit` commands will exit `gnuplot`.
165 166 167 168 |
# File 'lib/numo/gnuplot.rb', line 165 def quit send_cmd "quit" nil end |
#raise_plot(plot_window_nb = nil) ⇒ Object Also known as: raise
The ‘raise` command raises plot window(s)
138 139 140 141 |
# File 'lib/numo/gnuplot.rb', line 138 def raise_plot(plot_window_nb=nil) send_cmd "raise #{plot_window_nb}" nil end |
#refresh ⇒ Object
The ‘refresh` reformats and redraws the current plot using the data already read in.
172 173 174 175 |
# File 'lib/numo/gnuplot.rb', line 172 def refresh send_cmd "refresh" nil end |
#replot ⇒ Object
replot is not recommended, use refresh
69 70 71 72 |
# File 'lib/numo/gnuplot.rb', line 69 def replot run "replot\n#{@last_data}" nil end |
#reset(x = nil) ⇒ Object
The ‘reset` command causes all graph-related options that can be
set with the `set` command to take on their default values.
113 114 115 116 |
# File 'lib/numo/gnuplot.rb', line 113 def reset(x=nil) run "reset #{x}" nil end |
#set(*args) ⇒ Object
The ‘set` command is used to set lots of options.
75 76 77 78 |
# File 'lib/numo/gnuplot.rb', line 75 def set(*args) _set_unset("set",args) nil end |
#show(x) ⇒ Object
The ‘show` command shows their settings.
107 108 109 |
# File 'lib/numo/gnuplot.rb', line 107 def show(x) puts send_cmd "show #{x}" end |
#splot(*args) ⇒ Object
draws 2D projections of 3D surfaces and data.
53 54 55 56 |
# File 'lib/numo/gnuplot.rb', line 53 def splot(*args) _plot_splot("splot",args) nil end |
#to_s ⇒ Object
for irb workspace name
235 236 237 |
# File 'lib/numo/gnuplot.rb', line 235 def to_s "gnuplot" end |
#unset(*args) ⇒ Object
The ‘unset` command is used to return to their default state.
81 82 83 84 |
# File 'lib/numo/gnuplot.rb', line 81 def unset(*args) _set_unset("unset",args) nil end |
#var(name) ⇒ Object
‘var` returns Gnuplot variable (not Gnuplot command)
178 179 180 181 182 183 184 |
# File 'lib/numo/gnuplot.rb', line 178 def var(name) res = send_cmd("print #{name}").join("").chomp if /undefined variable:/ =~ res kernel_raise GnuplotError,res.strip end res end |