Connecting points with a line in TPtofile?

Hi everyone, I have a TProfile and I want to connect the points with a line (smooth or not). In TGraph I am able to achieve this through Draw(“ALP”) or just Draw(“AP”) and then Draw(“C”) etc. But it seems that none of those tricks work on TProfile ! It just ignores everything and plots just points and error bars… error bars are fine and I want them but I also would like to draw a line, how can I do that ?


TProfile are histograms. Option L or C should work. Use option HIST to avoid errors
so use option “HIST L” or "HIST C"
all details here:

[quote=“couet”]TProfile are histograms. Option L or C should work. Use option HIST to avoid errors
so use option “HIST L” or "HIST C"
all details here:[/quote]

That’s what I thought but it doesn’t seem to work ! And I need the error bars. so I tried to do:


That “C” option just seems to have no effect at all !

can you post a small script reproducing your problem ?

Here it is:

rando.cpp (3.66 KB)


I generate X values from -5 to +5, generate random numbers for Y values, collect them in x and y arrays of size “n_entr” (array wasn’t necessary for filling hist anf prof of course, but IO needed them for later, check line # 76). I fill TH2F *hist and TProfile *prof with these arrays and plot them. As I said, prof->Draw(“e1”); and then prof->Draw(“C”)’ or even Draw(“L”); doesn’t change anything . no lines drawn and is also true for the histogram !

In the next step (line # 76 onwards) I do my own averaging over beans and feed a TGraphErrors and show that “C” option works perfectly in TGraphErrors.


#include <iostream>
#include "TCanvas.h"
#include "TProfile.h"
#include "TROOT.h"
#include "TGraph.h"
#include "TH2.h"
#include "TGraphErrors.h"
#include "TStyle.h"
#include "TColor.h"
#include "TRandom3.h"

void rando()


    const int nbin = 30, n_entr = 1000;

    double xmin = -5., xmax = 5., y1 = 0., y2 =10., x[n_entr], y[n_entr], sum, sumSqr, xval, yval; // for filling TH2F and TPtofile
    int counts;
    double vx[nbin], vy[nbin], sigma2Y[nbin], errX[nbin], errY[nbin]; //necessary for my own averaging code for TGraphErrors

    TRandom3 r;

    TH2F *hist = new TH2F("hist", "2D Hist", nbin, xmin, xmax, nbin, y1, y2); //2D hist
    TProfile *prof = new TProfile("prof", "Prof", nbin, xmin, xmax, y1, y2); //Profile
    TCanvas  *canv = new TCanvas("canv", "Hist and Prof", 0, 0, 1000, 500);

    double dx = (xmax - xmin)/n_entr; // step size
    double bin_width = (xmax-xmin)/nbin; // bin width needed for the last part (TGraphErrors)

    for(int i = 0; i <= n_entr; ++i) // loop filling TH2F and TProfile

        x[i] = xmin + i*dx + dx/2; //arrays were not necessary but I needed them for another purpose
        y[i] = 10-r.Exp(4);

        hist->Fill(x[i], y[i]);
        prof->Fill(x[i], y[i]);


    // drawing TH2F------------------------------------------

    //drawing TProfile---------------------------------------
    //Fails to connect poibts by smooth curve or even just "L"
    prof->Draw("HIST L SAME");


You saved me… “HIST L SAME” works like a charm :smiley: thanks a lot.
But it’s clear that “ALP”, “C” etc that work for TGraph don’t apply to TProfile !

Yes that is clear from the doc.