Class: GnuplotRB::Multiplot
- Inherits:
-
Object
- Object
- GnuplotRB::Multiplot
- Includes:
- Plottable
- Defined in:
- lib/gnuplotrb/multiplot.rb
Overview
Multiplot allows to place several plots on one layout. It’s usage is covered in multiplot notebook.
Options
Most of Multiplot options are the same as in Plot so one can also set any options related to Plot and they will be considered by all nested plots (if they does not override it with their own values).
There are only 2 specific options:
-
title - set title for the whole layout (above all the plots)
-
layout - set layout size, examples:
{ layout : [1, 3] } # 3 plots, 1 row, 3 columns { layout : [2, 2] } # 4 plots, 2 rows, 2 columns
Direct Known Subclasses
Instance Attribute Summary collapse
-
#plots ⇒ Array
readonly
Array of plots contained by this object.
Instance Method Summary collapse
-
#[](*args) ⇒ Object
Equal to #plots.
-
#add_plots(*plots) ⇒ Multiplot
(also: #add_plot, #<<, #add)
Create new Multiplot with given plots added before plot at given position.
-
#add_plots!(*plots) ⇒ Multiplot
(also: #add_plot!, #add!)
Destructive version of #add_plots.
-
#initialize(*plots, **options) {|_self| ... } ⇒ Multiplot
constructor
A new instance of Multiplot.
-
#plot(term = nil, multiplot_part: false, **options) ⇒ Multiplot
Output all the plots to term (if given) or to this Multiplot’s own terminal.
-
#remove_plot(position = -1)) ⇒ Multiplot
(also: #remove)
Create new Multiplot without plot at given position (by default last plot is removed).
-
#remove_plot!(position = -1)) ⇒ Multiplot
(also: #remove!)
Destructive version of #remove_plot.
-
#replace_plot(position = 0, plot) ⇒ Multiplot
(also: #replace)
Create new Multiplot object where plot (Plot or Splot object) at position will be replaced with the given one.
-
#replace_plot!(position = 0, plot) ⇒ Multiplot
(also: #replace!, #[]=)
Destructive version of #replace_plot.
-
#update_plot(position = 0, **options) {|plot| ... } ⇒ Multiplot
(also: #update)
Create new updated Multiplot object where plot (Plot or Splot object) at position will be replaced with the new one created from it by updating.
-
#update_plot!(position = 0, **options) {|replacement| ... } ⇒ Multiplot
(also: #update!)
Destructive version of #update_plot.
Methods included from Plottable
#method_missing, #option_name, #option_name!, #own_terminal, #respond_to?, #title, #title!, #to_canvas, #to_gif, #to_iruby, #to_png, #to_specific_term, #to_svg, #xrange, #xrange!, #yrange, #yrange!
Methods included from OptionHandling
option_to_string, #options, #options!, ruby_class_to_gnuplot, string_key, valid_terminal?, validate_terminal_options
Constructor Details
#initialize(*plots, **options) {|_self| ... } ⇒ Multiplot
Returns a new instance of Multiplot.
27 28 29 30 31 32 |
# File 'lib/gnuplotrb/multiplot.rb', line 27 def initialize(*plots, **) @plots = plots[0].is_a?(Hamster::Vector) ? plots[0] : Hamster::Vector.new(plots) @options = Hamster::Hash[] OptionHandling.(@options) yield(self) if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class GnuplotRB::Plottable
Instance Attribute Details
#plots ⇒ Array (readonly)
Returns Array of plots contained by this object.
21 22 23 |
# File 'lib/gnuplotrb/multiplot.rb', line 21 def plots @plots end |
Instance Method Details
#[](*args) ⇒ Object
Equal to #plots
210 211 212 |
# File 'lib/gnuplotrb/multiplot.rb', line 210 def [](*args) @plots[*args] end |
#add_plots(*plots) ⇒ Multiplot Also known as: add_plot, <<, add
Create new Multiplot with given plots added before plot at given position. (by default it adds plot at the front).
150 151 152 153 |
# File 'lib/gnuplotrb/multiplot.rb', line 150 def add_plots(*plots) plots.unshift(0) unless plots[0].is_a?(Numeric) self.class.new(@plots.insert(*plots), @options) end |
#add_plots!(*plots) ⇒ Multiplot Also known as: add_plot!, add!
Destructive version of #add_plots.
167 168 169 170 171 |
# File 'lib/gnuplotrb/multiplot.rb', line 167 def add_plots!(*plots) plots.unshift(0) unless plots[0].is_a?(Numeric) @plots = @plots.insert(*plots) self end |
#plot(term = nil, multiplot_part: false, **options) ⇒ Multiplot
Output all the plots to term (if given) or to this Multiplot’s own terminal.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/gnuplotrb/multiplot.rb', line 42 def plot(term = nil, multiplot_part: false, **) = () do |plot_opts, mp_opts| plot_opts.merge(multiplot: mp_opts.to_h) end terminal = term || ([:output] ? Terminal.new : own_terminal) multiplot(terminal, ) if [:output] # guaranteed wait for plotting to finish terminal.close unless term # not guaranteed wait for plotting to finish # work bad with terminals like svg and html sleep 0.01 until File.size?([:output]) end self end |
#remove_plot(position = -1)) ⇒ Multiplot Also known as: remove
Create new Multiplot without plot at given position (by default last plot is removed).
187 188 189 |
# File 'lib/gnuplotrb/multiplot.rb', line 187 def remove_plot(position = -1) self.class.new(@plots.delete_at(position), @options) end |
#remove_plot!(position = -1)) ⇒ Multiplot Also known as: remove!
Destructive version of #remove_plot.
201 202 203 204 |
# File 'lib/gnuplotrb/multiplot.rb', line 201 def remove_plot!(position = -1) @plots = @plots.delete_at(position) self end |
#replace_plot(position = 0, plot) ⇒ Multiplot Also known as: replace
Create new Multiplot object where plot (Plot or Splot object) at position will be replaced with the given one.
116 117 118 |
# File 'lib/gnuplotrb/multiplot.rb', line 116 def replace_plot(position = 0, plot) self.class.new(@plots.set(position, plot), @options) end |
#replace_plot!(position = 0, plot) ⇒ Multiplot Also known as: replace!, []=
Destructive version of #replace_plot.
130 131 132 133 |
# File 'lib/gnuplotrb/multiplot.rb', line 130 def replace_plot!(position = 0, plot) @plots = @plots.set(position, plot) self end |
#update_plot(position = 0, **options) {|plot| ... } ⇒ Multiplot Also known as: update
Create new updated Multiplot object where plot (Plot or Splot object) at position will be replaced with the new one created from it by updating. To update a plot you can pass some options for it or a block, that should take existing plot (with new options if you gave them) and return a plot too.
Method yields new created Plot or Splot to allow you update it manually.
78 79 80 81 82 83 |
# File 'lib/gnuplotrb/multiplot.rb', line 78 def update_plot(position = 0, **) return self unless block_given? if .empty? replacement = @plots[position].() replacement = yield(replacement) if block_given? replace_plot(position, replacement) end |
#update_plot!(position = 0, **options) {|replacement| ... } ⇒ Multiplot Also known as: update!
Destructive version of #update_plot.
95 96 97 98 99 100 |
# File 'lib/gnuplotrb/multiplot.rb', line 95 def update_plot!(position = 0, **) return self unless block_given? if .empty? replacement = @plots[position].() yield(replacement) if block_given? self end |