// quick and non-optimised example of TGraphErrors/TGraphAsymmErrors not // displaying the error of the first point correctly in case one of the points' // errors are not contained within the displayed range void ErrorGraphFillStyle(){ gRandom = new TRandom3(5); TH1D *a = new TH1D("a", "a", 10, 0, 7); a->SetMaximum(12); a->SetMinimum(0); //set minimum to -10 to make sure errors don't go outside of range // a->SetMinimum(-10); Double_t xVal[10]; Double_t yVal[10]; Double_t xErr[10]; Double_t yErr[10]; //fill the values for(size_t i{1}; i <= a->GetNbinsX(); ++i){ std::cout << "Setting point " << i-1 << std::endl; xVal[i-1] = a->GetBinCenter(i); xErr[i-1] = a->GetBinWidth(i); yVal[i-1] = abs(gRandom->Uniform(0,7)); yErr[i-1] = abs(gRandom->Uniform(1,2)); } TGraphErrors *model = new TGraphErrors(10, xVal, yVal, xErr, yErr); TGraphErrors *model2 = new TGraphErrors(10, xVal, yVal, xErr, yErr); // same behaviour is observed in asymmetric graphs // TGraphAsymmErrors *model = new TGraphAsymmErrors(10, xVal, yVal, xErr, xErr, yErr, yErr); // TGraphAsymmErrors *model2 = new TGraphAsymmErrors(10, xVal, yVal, xErr, xErr, yErr, yErr); a->Draw(); model->SetFillColorAlpha(kBlue, 0.2); model2->SetFillColorAlpha(kRed, 0.2); model2->SetFillStyle(3154); model->SetFillStyle(1001); model->Draw("3,SAME"); model2->Draw("3,SAME"); }