Deprecated: Array and string offset access syntax with curly braces is deprecated in /mnt/hep_web/hep_web/member/n-kota/dokuwiki/inc/init.php on line 542
ja:root:wantto7 [GiriWiki]

ユーザ用ツール

サイト用ツール


ja:root:wantto7

以前のリビジョンの文書です



Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /mnt/hep_web/hep_web/member/n-kota/dokuwiki/inc/parser/handler.php on line 1458

Warning: Declaration of syntax_plugin_note::handle($match, $state, $pos, &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in /mnt/hep_web/hep_web/member/n-kota/dokuwiki/lib/plugins/note/syntax.php on line 79

Warning: Declaration of syntax_plugin_note::render($mode, &$renderer, $indata) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in /mnt/hep_web/hep_web/member/n-kota/dokuwiki/lib/plugins/note/syntax.php on line 101

Warning: preg_match(): Compilation failed: invalid range in character class at offset 3120 in /mnt/hep_web/hep_web/member/n-kota/dokuwiki/inc/parser/lexer.php on line 118
A PCRE internal error occured. This might be caused by a faulty plugin

===== 軸のラベルをtextにする ====== ---- === 元のラベルを飛ばして、手動でtextを配置する方法 === <code cpp> hist->GetXaxis()->SetLabelOffset(100); // 範囲外へ元の数字のラベルを飛ばしてしまう hist->GetXaxis()->SetNdivisions(3,1,1); TLatex *label = new TLatex(); label->SetTextSize(0.07); label->DrawLatexNDC(0.18,0.04,"K_{L}#rightarrow3#pi^{0}");// TLatexでtextを書いていく label->DrawLatexNDC(0.45,0.04,"K_{L}#rightarrow2#pi^{0}"); label->DrawLatexNDC(0.72,0.04,"K_{L}#rightarrow2#gamma"); </code> ---- === SetBinLabel functionを使う方法 === <code cpp> hist->GetXaxis()->SetBinLabel(1,"K_{L}#rightarrow3#pi^{0}");//第一引数はibin hist->GetXaxis()->SetBinLabel(2,"K_{L}#rightarrow2#pi^{0}");// ibin=0 はunderflow hist->GetXaxis()->SetBinLabel(3,"K_{L}#rightarrow2#gamma"); // ibin=nbin+1 はoverflow を表す hist->GetXaxis()->SetLabelSize(0.07); </code> フレームを書くまでのサンプルコード <code cpp> const Int_t NMode = 3; const TString LabelText[NMode] = { "K_{L}#rightarrow3#pi^{0}", "K_{L}#rightarrow2#pi^{0}", "K_{L}#rightarrow2#gamma" }; TH1D *frame = new TH1D("frame","",NMode,0,(Double_t)NMode); frame->SetBit(TH1::kNoStats); ///// X-axis ///// frame->GetXaxis()->SetNdivisions(NMode,1,1,false); frame->GetXaxis()->SetLabelSize(0.06); for(Int_t i = 0 ; i < NMode ; ++i) frame->GetXaxis()->SetBinLabel(i+1,LabelText[i]); ///// Y-axis ///// const Double_t Ymin = 0.2; const Double_t Ymax = 1.2; frame->SetMinimum(Ymin); frame->SetMaximum(Ymax); frame->SetYTitle("Y Title"); frame->SetTitleOffset(0.8,"Y"); frame->SetTickLength(0.01,"Y"); TCanvas *c = new TCanvas("c","c",800,600); c->SetTopMargin(0.1); c->SetBottomMargin(0.1); c->SetLeftMargin(0.1); c->SetRightMargin(0.05); frame->Draw(); </code> * フレームだけ書くにはstat. boxが出てくると邪魔なので、frame->SetBit(TH1::kNoStats)で出ないようにしておく。もちろんframe->SetStats(0)でもOK * frame->GetXaxis()->SetNdivisions(NMode,1,1,false)で、目盛が余計なところに出ないように設定。第4引数をfalseにしておくことで、rootが余計な気を利かせてくるのを阻止。 * frame->SetMinimum(Ymin), frame->SetMaximum(Ymax)でY軸の範囲を指定 * ラベルの文字数が多かったりすると文字が切れてしまったりするので、SetBottomMarginなどでpadの余白を調節。 == TPad::DrawFrame を使った場合 == DrawFrame functionで生成されるhistogramは、実はnbin=1000をもつ。 必要なbin数にまでrebinしてまとめてやった上でSetBinLabelを呼べば良い。\\ ただし、bin数が1000を割り切らない場合は、ラベルの位置が少々ずれてしまうのが難点。 上のサンプルコードのようにやる方がよいかな。 <code cpp> const Int_t NLabel = 3; const TString LabelText[NLabel] = { "K_{L}#rightarrow3#pi^{0}", "K_{L}#rightarrow2#pi^{0}", "K_{L}#rightarrow2#gamma" }; TCanvas *c = new TCanvas("c","c",700,500); TH1F *frame = (TH1F*)c->DrawFrame(0,3,3,4.5); frame->GetXaxis()->SetNdivisions(NLabel,1,1,false); frame->Rebin( frame->GetNbinsX()/NLabel ); for(Int_t i = 0 ; i < NLabel ; ++i) frame->GetXaxis()->SetBinLabel(i+1,LabelText[i]); frame->GetXaxis()->SetLabelSize(0.07); </code> ----

ja/root/wantto7.1534957823.txt.gz · 最終更新: 2018/08/22 17:10 by kota