Class: NumPlot::Dataset
- Inherits:
-
Object
- Object
- NumPlot::Dataset
- Defined in:
- lib/numplot.rb
Overview
The dataset class plotted by Plotter.
You can construct a dataset object using one of the following three methods:
-
Dataset.columns: construct a dataset from columns
-
Dataset.rows: construct a dataset from rows
-
Dataset.histogram: construct a histogram dataset
You need to choose from Dataset.columns and Dataset.rows according to the arrangement of your data.
The dataset object is registered to Plotter object using Plotter#add_dataset.
Parameters for a dataset
When you call Dataset.columns, Dataset.rows, or Dataset.histogram, you can give some parameters to determine the style of plotting. The parameters are as follows. If you know the details of these parameters, please read the gnuplot documents.
-
title: “TITLE” or notitle: true
-
with: “points”, “dots”, etc.
-
axis:
-
linestyle: a style number (ls: is also available)
-
linetype: a line type number
-
linewidth: a line width multiplier (default is 1.0), (lw: is also available)
-
linecolor: a color number or an RGB object. (lc: is also available)
-
pointtype: a point type number (pt: is also available)
-
pointsize: a point size multiplier (default is 1.0), (ls: is also available)
-
fill: a fill style (fs: is also available)
-
nohidden3d: true if you need to activate this option
-
nocontours: true if you need to activate this option
-
nosurface: true if you need to activate this option
Constant Summary
Class Method Summary (collapse)
-
+ (Dataset) columns(data, opts = {})
Construct a dataset object form columns.
-
+ (Dataset) histogram(data, opts = {})
(also: histo)
Construct a histogram dataset object.
-
+ (Dataset) lines(data, opts = {})
Construct a dataset object from a sequence of sequences of rows.
-
+ (Dataset) rows(data, opts = {})
Construct a dataset object form rows.
Instance Method Summary (collapse)
-
- (Dataset) initialize(data, opts = {})
constructor
A new instance of Dataset.
Constructor Details
- (Dataset) initialize(data, opts = {})
A new instance of Dataset
496 497 498 499 |
# File 'lib/numplot.rb', line 496 def initialize(data, opts={}) @data = data @opts = opts end |
Class Method Details
+ (Dataset) columns(data, opts = {})
Construct a dataset object form columns.
If your data are xs = [x0, x1, x2, … ] and ys = [y0, y1, y2, …], you should use this method as: Dataset.columns([xs, ys])
If your data is transposed, you need to use columns instead of this method.
You can give some parameters as a hash to set a plotting style. Please see NumPlot::Dataset.
516 517 518 |
# File 'lib/numplot.rb', line 516 def self.columns(data, opts={}) new(data.map(&:to_a).transpose, opts) end |
+ (Dataset) histogram(data, opts = {}) Also known as: histo
Construct a histogram dataset object.
You need to give some parameters to construct a histogram.
-
dim: the dimension of your data, now only 1-dim data is supported (default is 1)
-
binsize: the bin size (required, Numeric)
-
base: the coordinate of a center of a bin (default is 0.0). If binsize = 1.0 and base = 0.0, the bins are …, [-1.5, -0.5), [-0.5, 0.5), [0.5, 1.5), … . If binsize = 1.0 and base = 0.5, the bins are …, [-1.0, 0.0), [0.0, 1.0), … .
-
histogram_style: You can choose one of the following normalization scheme:
-
:count not normalized
-
:ratio normailized to the number of data points
-
:density normalized to (the number of data points)*(binsize). You choose this option if you want to show the probability density function from the data.
-
-
cumulative: construct a cumulative histogram if true. If the cumulative option is true, the meaning of histogram_style option is changed.
-
:count not normalized
-
:ratio, :density normalized by the number of data, this means that the maximum value of a cumulative histogram is normalized to 1.
-
You can also give some other parameters to determine a plotting style. See NumPlot::Dataset for details.
599 600 601 602 603 604 605 606 607 608 |
# File 'lib/numplot.rb', line 599 def self.histogram(data, opts={}) case opts.fetch(:dim, 1) when 1 histo1d(data, opts) when 2 raise NotImplementedError, "Histogram for 2D data is not implemented yet" else raise ArgumentError, "You can use only 1D or 2D histogram data" end end |
+ (Dataset) lines(data, opts = {})
Construct a dataset object from a sequence of sequences of rows
If your data is like [[[x00, y00] [x01, y01], … ], [[x10, y10], [x11, y11], …], ..] you should use this method.
You can give some parameters as a hash to set a plotting style. Please see NumPlot::Dataset for details.
551 552 553 554 555 556 557 |
# File 'lib/numplot.rb', line 551 def self.lines(data, opts={}) data = data.map{|lines| lines.to_a + [[]] }.flatten(1) p data new(data, opts) end |
+ (Dataset) rows(data, opts = {})
Construct a dataset object form rows.
If your data is [[x0, y0], [x1, y1], …], you should use this method as: Dataset.rows(data)
If your data is transposed, you need to use rows instead of this method.
You can give some parameters as a hash to set a plotting style. Please see NumPlot::Dataset for details.
535 536 537 |
# File 'lib/numplot.rb', line 535 def self.rows(data, opts={}) new(data.map(&:to_a), opts) end |