Class: Digiproc::QuickPlot
- Inherits:
-
Object
- Object
- Digiproc::QuickPlot
- Extended by:
- Plottable::ClassMethods
- Defined in:
- lib/quick_plot.rb
Overview
Class for quickly plotting data
Class Method Summary collapse
-
.lambda_plot(label = "1") ⇒ Object
Plots a lambda plot.
-
.pi_plot(label = "0.5") ⇒ Object
Plots a pi plot.
-
.plot(x: nil, y: nil, data: nil, title: nil, x_label: nil, y_label: nil, labels: nil, data_name: "data", label_map: nil, dark: false, path: "./plots/") ⇒ Object
Quickly plot data.
-
.plot_eq(eqn:, sample_times:, title: nil, x_label: nil, y_label: nil) ⇒ Object
- Plots an input equation (lambda) == Input args eqn
- lambda, equation to pe plotted sample_times
- Array input values to lambda equation title (Optional)
- String x_label (Optional)
- String y_label (Optional)
-
String.
- .step ⇒ Object
Instance Method Summary collapse
Methods included from Plottable::ClassMethods
Class Method Details
.lambda_plot(label = "1") ⇒ Object
Plots a lambda plot
58 59 60 61 62 |
# File 'lib/quick_plot.rb', line 58 def self.lambda_plot(label = "1") eqn = ->(t){ t.abs <= 1 ? (1 - t.abs) : 0} x = Digiproc::Functions.linspace(-2, 2, 102) plot(data: x.map{|t| eqn.call(t)},title: "Lambda fn" ,labels: {26 => "-#{label}", 51 => 0 ,76 => label}) end |
.pi_plot(label = "0.5") ⇒ Object
Plots a pi plot
47 48 49 50 51 52 53 |
# File 'lib/quick_plot.rb', line 47 def self.pi_plot(label ="0.5") z = Digiproc::Functions.zeros(26) o = Digiproc::Functions.ones(50) y = z + o + z x = Digiproc::Functions.linspace(-2, 2, 102) plot(x: x, y: y, title: "PI fn" ,labels: {-1 => "-#{label}", 0 => "0", 1 => label}) end |
.plot(x: nil, y: nil, data: nil, title: nil, x_label: nil, y_label: nil, labels: nil, data_name: "data", label_map: nil, dark: false, path: "./plots/") ⇒ Object
Quickly plot data. Either data OR x AND y are required. If just data is inputted, x values will be the index of the value in the data array
Input Args
- x
-
Array (required if data is not included)
- y
-
Array (required if data is not included)
- data
-
Array (required if x and y are not included)
- title (Optional)
-
String
- x_label (Optional)
-
String
- y_label (Optional)
-
String
- labels (Optional)
-
Array x value labels
- data_name (Optional)
-
name of data for legend
- label_map (Optional)
-
Lambda - mapping data index to an x label for that index
- dark (Optional)
-
Boolean - whether or not to use dark mode (defaults to false)
- path (Optional)
-
Path to save plot picture to. Defauilts to “./plots”
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/quick_plot.rb', line 23 def self.plot(x: nil,y: nil, data: nil, title: nil, x_label: nil, y_label: nil, labels: nil, data_name: "data", label_map: nil, dark: false, path: "./plots/") xyname, dataname = nil, nil if not x.nil? if evenly_spaced?(x) label_map = Digiproc::Functions.map_to_eqn(0, x.length, x.min, x.max) data = y y, x = nil, nil end end data.nil? ? (xyname = data_name) : (dataname = data_name) qplot(x: x, y: y, data: data, data_name: dataname, xyname: xyname, label_map: label_map, filename: to_filename(title), path: path) do |g| g.title = title if not title.nil? g.x_axis_label = x_label if not x_label.nil? g.y_axis_label = y_label if not y_label.nil? g.labels = labels if not labels.nil? g.theme = Digiproc::Plottable::Styles::MIDNIGHT if dark end end |
.plot_eq(eqn:, sample_times:, title: nil, x_label: nil, y_label: nil) ⇒ Object
Plots an input equation (lambda)
Input args
- eqn
-
lambda, equation to pe plotted
- sample_times
-
Array input values to lambda equation
- title (Optional)
-
String
- x_label (Optional)
-
String
- y_label (Optional)
-
String
72 73 74 75 |
# File 'lib/quick_plot.rb', line 72 def self.plot_eq(eqn: , sample_times: ,title: nil, x_label: nil, y_label: nil) data = process(eqn, sample_times) plot(data: data, title: title, x_label: x_label, y_label: y_label) end |
.step ⇒ Object
42 43 |
# File 'lib/quick_plot.rb', line 42 def self.step() end |
Instance Method Details
#process(eqn, locations) ⇒ Object
77 78 79 |
# File 'lib/quick_plot.rb', line 77 def process(eqn, locations) locations.map{ |n| eqn.call(n) } end |