How to fill 2D histogram

Hello Experts,

I defined a 2D histogram as:

TH2F *h3 = new TH2F("h3", "Hist", 100, 0., 1.E5, 100, 1., 2.E7);

I have two outputs such as energy and flux. I want to fill energy and flux in X and Y axes respectively. So fill the histogram as:

h3->Fill(energy, flux);

Canvas defined as:

TCanvas *c1 = new TCanvas("c1"); c1->cd(); h3->Draw("AP");

However It does not fill properly in 2D. Kindly help me how to fill 2D histogram?

Thanks,
Anil

What do you mean by “does not fill properly”? what do you get? It’s better if you show all the code you are trying and what you get. Anyway, the lines you show seem ok, but:
1 - Make sure that energy and flux have values within the x and y ranges of the histo (and I suppose they are getting the values inside a loop).
2 - I don’t think the option “A” is valid when drawing a histogram, so remove that; and instead of “P” try h3->Draw("*"); to see the data points more clearly at least initially.

AP are not valid options to draw 2D histograms (I bet you copied that from a TGraph drawing). I would suggest you try:

h3->Draw("COL");

or:

h3->Draw("BOX");

Thank you @couet and @dastudillo
First I used h3->Draw(“COL”), but later i wished fill the histogram in line/point format. So i tried to use AP option from TGraph :grinning:, unfortunately it did not work. The “*” option also does not clearly visible.
I like to fill the 2D histogram as:

Is there any option available for this in 2D?

This kind of plot is not possible with 2D histograms simply because this kind of plot represent unbinned dat whereas 2D histograms are binned data. Use a TGraph instead.

Ok @couet thank you.