lib/numru/ganalysis/histogram.rb in gphys-1.1.1 vs lib/numru/ganalysis/histogram.rb in gphys-1.2.2

- old
+ new

@@ -152,11 +152,11 @@ module GGraph module_function @@histogram_options = Misc::KeywordOptAutoHelp.new( - ['window', [nil,nil,0,nil], "window bounds"], + ['window', [nil,nil,nil,nil], "window bounds"], ['title', "histogram", "window title"], ['exchange', false, "exchange x and y"], ['fill', false, "fill bars"] ) def histogram(gphys, newframe=true, options=nil) @@ -168,34 +168,92 @@ raise ArgumentError, "rank of gphys must be 1" end unless gphys.axis(0).cell? raise ArgumentError, "axis must be cell type" end + # if window is specified via GGraph#fig or GGraph#set_fig, use it. opts = @@histogram_options.interpret(options) exchange = opts["exchange"] + window = opts["window"] || @@fig['window'] unless exchange x = gphys.axis(0).cell_bounds y = gphys + window[2] ||= 0 else y = gphys.axis(0).cell_bounds x = gphys + window[0] ||= 0 end + itr = @@fig['itr'] || DCL::sgpget("itr") + if (itr==2 || itr==4) + tmp = y.val + if tmp.min * tmp.max < 0 + if tmp.min.abs < tmp.max + mask = tmp.lt(0) + else + mask = tmp.gt(0) + end + else + mask = tmp.ne(0) + end + if tmp.is_a?(NArrayMiss) + tmp.set_mask(mask * tmp.get_mask) + else + tmp = NArrayMiss.to_nam_no_dup(tmp, mask) + end + y.replace_val(tmp) + window[2] = tmp.abs.min * (tmp.min < 0 ? -1 : 1) + end + if (itr==3 || itr==4) + tmp = x.val + if tmp.min * tmp.max < 0 + if tmp.min.abs < tmp.max + mask = tmp.lt(0) + else + mask = tmp.gt(0) + end + else + mask = tmp.ne(0) + end + if tmp.is_a?(NArrayMiss) + tmp.set_mask(mask * tmp.get_mask) + else + tmp = NArrayMiss.to_nam_no_dup(tmp, mask) + end + x.replace_val(tmp) + window[0] = tmp.abs.min * (tmp.min < 0 ? -1 : 1) + end + opts["window"] = window + if newframe fig(x, y, "window"=>opts["window"]) axes(x, y, "title"=>opts["title"]) end + lmiss = DCL::gllget("lmiss") + DCL::gllset("lmiss", true) unless exchange if opts["fill"] - DCL::uvbxa(x.val, [0]*y.length, y.val) + DCL::uvbxa(x.val, [window[2]] * y.length, y.val) end - DCL::uvbxf(x.val, [0]*y.length, y.val) + if (itr == 2) || (itr == 4) + bottom = [y.val.min] * y.length + else + bottom = [window[2]] * y.length + end + DCL::uvbxf(x.val, bottom, y.val) else if opts["fill"] - DCL::uhbxa([0]*x.length, x.val, y.val) + DCL::uhbxa([window[0]] * x.length, x.val, y.val) end - DCL::uhbxf([0]*x.length, x.val, y.val) + if (itr == 3) || (itr == 4) + bottom = [x.val.min] * x.length + else + bottom = [window[0]] * x.length + end + DCL::uhbxf(bottom, x.val, y.val) end + DCL::gllset("lmiss", lmiss) return nil end alias :histogram1D :histogram end @@ -239,9 +297,19 @@ DCL::gropn(4) hist = GAnalysis.histogram(gphys1D) GGraph.histogram(hist) + GGraph.set_fig("itr"=>2) + GGraph.histogram(hist) + + GGraph.set_fig("itr"=>3) + GGraph.histogram(hist) + + GGraph.set_fig("itr"=>4) + GGraph.histogram(hist) + + GGraph.set_fig("itr"=>1) hist = gphys1D.histogram("nbins"=>10) GGraph.histogram(hist, true, "title"=>"histogram 1D") hist = GAnalysis.histogram2D(gphys2D_0, gphys2D_1, "nbins0"=>50) GGraph.tone(hist, true, "tonc"=>true)