Class: GnuPlotter
- Inherits:
-
Object
- Object
- GnuPlotter
- Defined in:
- lib/gnuplotter.rb,
lib/gnuplotter/version.rb
Defined Under Namespace
Classes: DataSet
Constant Summary collapse
- NOQUOTE =
Quotes around the values of the below keys are stripped.
[ :auto, :autoscale, :cbrange, :border, :boxwidth, :datafile, :grid, :key, :linetype, :logscale, :nocbtics, :palette, :rtics, :terminal, :tic, :style, :view, :yrange, :ytics, :xrange, :xtics, :ztics ]
- VERSION =
"1.0.2"
Instance Method Summary collapse
-
#add_dataset(options = {}) {|dataset| ... } ⇒ Object
Method to add a dataset to the current GnuPlot.
-
#initialize ⇒ GnuPlotter
constructor
Constructor method for a GnuPlot object.
-
#plot ⇒ Object
Method to execute the plotting of added datasets.
-
#set(options) ⇒ Object
Method to set an option in the GnuPlot environment e.g: set(title: “Nobel Prize”) set(grid: :true) # note no such thing as set(grid).
-
#splot ⇒ Object
Method to execute the splotting of added datasets.
-
#to_gp(cmd = "plot") ⇒ Object
Method that returns a GnuPlot script as a list of lines.
-
#unset(options) ⇒ Object
Method to unset an option in the GnuPlot environment e.g: unset(ytics: true) # note no such thing as unset(ytics).
Constructor Details
#initialize ⇒ GnuPlotter
Constructor method for a GnuPlot object.
59 60 61 62 |
# File 'lib/gnuplotter.rb', line 59 def initialize @options = Hash.new { |h1, k1| h1[k1] = Hash.new { |h2, k2| h2[k2] = [] } } @datasets = [] end |
Instance Method Details
#add_dataset(options = {}) {|dataset| ... } ⇒ Object
Method to add a dataset to the current GnuPlot.
add_dataset(using: "1:2:3:4", with: "vectors nohead", title: "'bar'") do |plotter|
data.map { |d| plotter << d }
end
109 110 111 112 113 114 115 116 |
# File 'lib/gnuplotter.rb', line 109 def add_dataset( = {}) raise GnuPlotterError, "No block given" unless block_given? dataset = DataSet.new() @datasets << dataset yield dataset end |
#plot ⇒ Object
Method to execute the plotting of added datasets. Any plot data, i.e. dumb terminal, is returned.
120 121 122 |
# File 'lib/gnuplotter.rb', line 120 def plot gnuplot("plot") end |
#set(options) ⇒ Object
Method to set an option in the GnuPlot environment e.g: set(title: “Nobel Prize”) set(grid: :true) # note no such thing as set(grid).
67 68 69 70 71 72 73 74 75 |
# File 'lib/gnuplotter.rb', line 67 def set() raise GnuPlotterError, "Non-hash options given" unless .is_a? Hash .each do |key, value| @options[:set][key.to_sym] << value end self end |
#splot ⇒ Object
Method to execute the splotting of added datasets. Any plot data, i.e. dumb terminal, is returned.
126 127 128 |
# File 'lib/gnuplotter.rb', line 126 def splot gnuplot("splot") end |
#to_gp(cmd = "plot") ⇒ Object
Method that returns a GnuPlot script as a list of lines.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/gnuplotter.rb', line 90 def to_gp(cmd = "plot") if ! @datasets.empty? data_lines = [] @datasets.each do |dataset| data_lines.push(*dataset.format_data, "e") dataset.delete end plot_settings + [data_settings(cmd, true)] + data_lines else plot_settings end end |
#unset(options) ⇒ Object
Method to unset an option in the GnuPlot environment e.g: unset(ytics: true) # note no such thing as unset(ytics).
79 80 81 82 83 84 85 86 87 |
# File 'lib/gnuplotter.rb', line 79 def unset() raise GnuPlotterError, "Non-hash options given" unless .is_a? Hash .each do |key, value| @options[:unset][key.to_sym] << value || true end self end |