Assigning the same magnetic field strength to a colorbar at a contour plot


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.22/00
Platform: Ubuntu 20.04.1 LTS (WSL2)
Compiler: GNU or GCC


I have created a contour plot of the magnetic flux density of an octupole magnet. I have created multiple contour plots, but I want to assign them the same color so that I can more easily compare the plots. I don’t want the colors assigned to the magnetic field strength to vary across the plots, how do I do so that is not the case?

void Contour_Plot(){

const Int_t NCont = 20;
gStyle->SetNumberContours(NCont);
auto g = new TGraph2D(“Contour_data.txt”,“%lg %lg %lg”);

g->SetNpx(200);
g->SetNpy(200);
g->SetTitle(“Contour plot of the magnetic flux density (T) in the x-y plane”);

Double_t r2 = std::pow(0.050, 2.); // radius squared
for (Int_t i = g->GetN() - 1; i >= 0; i–)
if (std::pow(g->GetX()[i], 2.) + std::pow(g->GetY()[i], 2.) > std::pow(0.050, 2.)) g->RemovePoint(i);

g->GetHistogram()->GetXaxis()->SetTitle(“x (m)”);
g->GetHistogram()->GetYaxis()->SetTitle(“y (m)”);
g->SetLineWidth(1);
g->SetLineStyle(1);

TCanvas *c = new TCanvas(“c”, “c”);
g->Draw(“COLZ”);
c->SetRealAspectRatio();
c->Modified(); c->Update();

TEllipse *e = new TEllipse(0., 0., 0.050); e->SetFillStyle(0); e->Draw();
gPad->Modified(); gPad->Update();

}

Choose appropriate “z_min” and “z_max” values and then (for each graph “g”):
g->SetMinimum(z_min); g->SetMaximum(z_max);

Thanks, it worked