Module: UnifiedPlot
- Defined in:
- lib/unifiedPlot.rb
Constant Summary collapse
- PLOT_DEFAULTS =
{ :grid => true, :ylabel => nil, :y2label => nil, :xlabel => nil, :x2label => nil, :key => 'bottom out', :xsize => 1200, :ysize => 800, :font => 'arial', :fontsize => 10, }
- DATA_DEFAULTS =
{ :title => '', :style => 'linespoints', :axes => 'x1y1', }
Class Method Summary collapse
- .fieldPlot(inputs) ⇒ Object
- .heatMap(inputs, plotConf = PLOT_DEFAULTS, title = '', oType = 'x11', oName = 'test') ⇒ Object
- .histogram(inputs) ⇒ Object
-
.linePlot(inputs, plotConf = PLOT_DEFAULTS, title = '', oType = 'x11', oName = 'test') ⇒ Object
input elements: data = { :y => […], (required) :x => […], (optional) :axes => ‘x2y1’, (optional) :title => ‘…’, :style => ‘lines’, } plot = { :xlabel => ”, :ylabel => ”, :title => ”, :grid => false, }.
- .pm3d(inputs, plotConf = PLOT_DEFAULTS, title = '', oType = 'x11', oName = 'test') ⇒ Object
Class Method Details
.fieldPlot(inputs) ⇒ Object
146 147 148 149 150 151 |
# File 'lib/unifiedPlot.rb', line 146 def UnifiedPlot.fieldPlot(inputs) RubyPython.start pl = RubyPython.import('pylab') pl.imshow(inputs.to_a.reverse) pl.show() end |
.heatMap(inputs, plotConf = PLOT_DEFAULTS, title = '', oType = 'x11', oName = 'test') ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/unifiedPlot.rb', line 109 def UnifiedPlot.heatMap(inputs,plotConf = PLOT_DEFAULTS,title = '',oType = 'x11',oName = 'test') plotConf = PLOT_DEFAULTS.merge(plotConf) Gnuplot.open do |gp| Gnuplot::Plot.new( gp ) do |plot| unless 'x11' == oType plot.terminal oType plot.output "#{oName}.#{oType}" end plot.title title UnifiedPlot.applyConf(plot,plotConf) plot.xtics plot.ytics inputs.each {|data| data = DATA_DEFAULTS.merge(data) dataset = [data[:x].to_a,data[:y].to_a,data[:z].to_a] plot.data << Gnuplot::DataSet.new( dataset ) do |ds| ds.with = 'image' ds.axes = data[:axes] ds.title = data[:title] end } plot.grid end end return ('x11' != oType) ? [oName,oType].join('.') : nil end |
.histogram(inputs) ⇒ Object
139 140 141 142 143 144 145 |
# File 'lib/unifiedPlot.rb', line 139 def UnifiedPlot.histogram(inputs) nbins = 100 max = inputs[:y].abs.max h = GSL::Histogram.alloc(nbins, [-max, max]) h.fill(inputs[:y]) GSL::graph(h) end |
.linePlot(inputs, plotConf = PLOT_DEFAULTS, title = '', oType = 'x11', oName = 'test') ⇒ Object
input elements: data =
:y => [...], (required)
:x => [...], (optional)
:axes => 'x2y1', (optional)
:title => '...',
:style => 'lines',
plot = {
:xlabel => '',
:ylabel => '',
:title => '',
:grid => false,
}
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/unifiedPlot.rb', line 39 def UnifiedPlot.linePlot(inputs, plotConf =PLOT_DEFAULTS, title ='', oType ='x11',oName ='test') # allow hash input inputs = [inputs] if inputs.kind_of? Hash plotConf = PLOT_DEFAULTS.merge(plotConf) unless plotConf == PLOT_DEFAULTS Gnuplot.open do |gp| Gnuplot::Plot.new( gp ) do |plot| unless 'x11' == oType plot.terminal "#{oType} size #{plotConf[:xsize]},#{plotConf[:ysize]} font #{plotConf[:font]} #{plotConf[:fontsize]}" plot.output "#{oName}.#{oType}" end plot.title title UnifiedPlot.applyConf(plot,plotConf) plot.xtics plot.ytics inputs.each {|data| data = DATA_DEFAULTS.merge(data) dataset = data.has_key?(:x) ? [data[:x].to_a,data[:y].to_a] : data[:y].to_a plot.data << Gnuplot::DataSet.new( dataset ) do |ds| ds.with = data[:style] ds.axes = data[:axes] plot.x2tics 'in' if data[:axes][0,2] == 'x2' plot.y2tics 'in' if data[:axes][-2..-1] == 'y2' ds.title = data[:title] end } plot.grid end end return ('x11' != oType) ? [oName,oType].join('.') : nil end |
.pm3d(inputs, plotConf = PLOT_DEFAULTS, title = '', oType = 'x11', oName = 'test') ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/unifiedPlot.rb', line 75 def UnifiedPlot.pm3d(inputs,plotConf = PLOT_DEFAULTS,title = '',oType = 'x11',oName = 'test') Gnuplot.open do |gp| Gnuplot::SPlot.new( gp ) do |plot| unless 'x11' == oType plot.terminal oType plot.output "#{oName}.#{oType}" end plotConf = PLOT_DEFAULTS.merge(plotConf) plot.title title UnifiedPlot.applyConf(plot,plotConf) plot.xtics plot.ytics # write stuff to a file filename = `tempfile`.chomp File.open(filename,'w') {|f| inputs.each {|data| f << data.join(' ') f << "\n" } } plot.view "map" plot.data << Gnuplot::DataSet.new("'"+filename+"'") do |ds| ds.with = "image" ds.matrix = true end end end return ('x11' != oType) ? [oName,oType].join('.') : nil end |