#include#include void plot_histogram() { TH1F *hist = new TH1F("hist", "Example Histogram", 10, 0, 10); hist->Fill(2); hist->Fill(3); hist->Fill(3); hist->Fill(5); hist->SetMarkerColor(kRed); TCanvas *canvas = new TCanvas("canvas", "Canvas", 800, 600); hist->Draw("P"); canvas->SaveAs("histogram.png"); }
#includeThis example shows a use case where we create a random normal distribution with a mean of 0 and a standard deviation of 1, and fill a histogram with 100 bins ranging from -5 to 5 with 10,000 random samples. We set the marker color to blue and draw the histogram with the "P" option. The resulting plot is saved to a file named "random_histogram.png".#include #include void plot_random_histogram() { TH1F *hist = new TH1F("hist", "Random Histogram", 100, -5, 5); TRandom3 random_generator; for (int i = 0; i < 10000; i++) { hist->Fill(random_generator.Gaus(0, 1)); } hist->SetMarkerColor(kBlue); TCanvas *canvas = new TCanvas("canvas", "Canvas", 800, 600); hist->Draw("P"); canvas->SaveAs("random_histogram.png"); }