Hi!
If you run this:
vector<Double_t> x = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
vector<Double_t> y = {1, 2, 3, 4, 3, 6, 7, 0, 0, 4};
void test () {
TCanvas * c = new TCanvas("name", "window", 800, 600);
c->SetGrid();
gStyle->SetOptStat(false);
TH1D * h = new TH1D("name", ";angle [#circ];probability [#]", y.size(), 0, y.size());
for (Int_t i = 0; i < y.size(); i++) h->SetBinContent(i + 1, y[i]);
h->SetFillColor(2);
h->Draw("HIST BAR");
x.clear();
y.clear();
}
you get this graph:
but I have the need to highlight an area of the graph, so that i looks like this:
How to do that in root?
Thank you!
One of the possible ways is to add in the end:
gPad->Modified(); gPad->Update();
TBox *b =
new TBox(7., gPad->GetUymin(),
9., (999. * gPad->GetUymax() + gPad->GetUymin()) / 1000.);
b->SetFillColor(7);
b->Draw();
gPad->RedrawAxis(); gPad->RedrawAxis("G");
gPad->Modified(); gPad->Update();
Of course, maybe @couet knows something more elegant.
2 Likes
Uhm.
I see it works. Quite simple and effective, so thatâs ok!
Thank you!
@couet It seems to me that there is no way to redraw the âborderâ lines (thatâs why I couldnât simply use âgPad->GetUymax()
â and I had to lower the top edge of the box). Maybe you could add this feature.
couet
May 4, 2020, 11:19am
6
Something like that ?
vector<Double_t> x = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
vector<Double_t> y = {1, 2, 3, 4, 3, 6, 7, 0, 0, 4};
void RedrawFrame(){
auto b = new TBox(gPad->GetUxmin(), gPad->GetUymin(),
gPad->GetUxmax(), gPad->GetUymax());
b->SetFillStyle(0);
b->SetLineWidth(gPad->GetFrameLineWidth());
b->SetLineColor(gPad->GetFrameLineColor());
b->Draw();
}
void ziel () {
TCanvas * c = new TCanvas("name", "window", 800, 600);
c->SetGrid();
gStyle->SetOptStat(false);
TH1D * h = new TH1D("name", ";angle [#circ];probability [#]", y.size(), 0, y.size());
for (Int_t i = 0; i < y.size(); i++) h->SetBinContent(i + 1, y[i]);
h->SetFillColor(2);
h->Draw("HIST BAR");
gPad->Modified(); gPad->Update();
auto b = new TBox(7., gPad->GetUymin(),
9., gPad->GetUymax());
b->SetFillColor(7);
b->Draw();
gPad->RedrawAxis();
gPad->RedrawAxis("G");
RedrawFrame();
}
1 Like
So, Iâve been thinking about a new option, something like (note: sometimes âBBâ or âFBâ drawing options are effective so the complete borders may not need to be redrawn):
gPad->RedrawAxis("B"); // redraw "active" Borders / BoundingBox
1 Like
couet
May 4, 2020, 11:34am
8
Yes thatâs a idea to put it as a new option in RedrawAxis. I was posting it as an example to check if that is the functionality needed. If yes, that code can go in RedrawAxisâŚ
Uhm, so you basically redraw the main pad too in that additional method RedrawFrame()?
This is a bit more polish since it isnât affected by the canvas size.
Thanks.
couet
May 4, 2020, 3:26pm
10
This idea would be to pout that code in RedrawAxis under the option "F"rame or "B"ox
couet
May 5, 2020, 8:26am
12
This new option is now in master. Thanks for the suggestion.
system
Closed
May 19, 2020, 8:26am
13
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.