class STFTSpectrogram::Plot
Creates plots using gnuplot
Constants
- TEMP_SPECTR_DAT_FILE
- TEMP_SPECTR_IMG_FILE
Attributes
imgfile[R]
Public Class Methods
new()
click to toggle source
# File lib/plot/plot.rb, line 12 def initialize @imgfile = Tempfile.new([TEMP_SPECTR_IMG_FILE, '.png']) @imgfile.close set_gnuplot_defaults end
Public Instance Methods
build_term_str(w, h, fnt_size)
click to toggle source
# File lib/plot/plot.rb, line 47 def build_term_str(w, h, fnt_size) 'png font arial ' + fnt_size.to_s + ' size ' + w.to_s + ',' + h.to_s end
plot(x, y, w = 1920, h = 1080, fnt_size = 12)
click to toggle source
Plots data contained int x and y parameters
# File lib/plot/plot.rb, line 68 def plot(x, y, w = 1920, h = 1080, fnt_size = 12) outfile = @imgfile.path termstr = build_term_str(w, h, fnt_size) Numo.gnuplot do set term: termstr set output: outfile set autoscale: 'xfix' set autoscale: 'yfix' set autoscale: 'cbfix' plot x, y, w: 'lines', t: '', lc_rgb: 'red' unset :output end end
plot_matrix(data, w = 1920, h = 1080, fnt_size = 12)
click to toggle source
Plots data in a matrix format using a temporary file Data are plotted to 2D with their magnitude being differentiated by color gradient
# File lib/plot/plot.rb, line 54 def plot_matrix(data, w = 1920, h = 1080, fnt_size = 12) tmpfile = write_temp_data(data) outfile = @imgfile.path termstr = build_term_str(w, h, fnt_size) Numo.gnuplot do set term: termstr set output: outfile plot "'" + tmpfile.path + "'", :matrix, w: 'image', t: '' unset :output end tmpfile.unlink end
write_temp_data(data)
click to toggle source
# File lib/plot/plot.rb, line 40 def write_temp_data(data) datafile = Tempfile.new(TEMP_SPECTR_DAT_FILE) datafile.write(data.map { |row| row.join(' ') }.join("\n")) datafile.close datafile end
xtics=(str)
click to toggle source
Sets x axis tics
# File lib/plot/plot.rb, line 31 def xtics=(str) Numo.gnuplot { set xtics: str } end
ytics=(str)
click to toggle source
Sets y axis tics
# File lib/plot/plot.rb, line 36 def ytics=(str) Numo.gnuplot { set ytics: str } end
Private Instance Methods
set_gnuplot_defaults()
click to toggle source
# File lib/plot/plot.rb, line 18 def set_gnuplot_defaults Numo.gnuplot do set title: '' set palette: 'rgb 34,35,36' set cblabel: 'Magnitude' set xtics: 'auto' set ytics: 'auto' set xlabel: 'Time (s)' set ylabel: 'Frequency (kHz)' end end