Contour plot advice


I am needing to make some contour plots and exploring the options available in ROOT. The data I am looking to plot is in YXZ format in the following file:

40Ca_208Pb_39K_Ex_115deg.txt (55.0 KB)

This an example, I need to make several plots and generally the data is pretty noisy. I am trying to make these plots using TGraph2D.

I like the look of the resulting figure when using the CONT4 option, as seen in the image below. However, for some reason I get a weird discontinuity in around Y = 0.99. This doesn’t seem to arise from the data so I am quite puzzled as to why this is appearing.

Alternatively I have tried the TRI2 option, which seems to smooth out this weird feature. However, I want to view the plot in the XY plane. To do this, I need to use:


To get the plot in the correct orientation. However, this seems to invert the X and Y axes :confounded: This is shown below:

Does anyone have any suggestions to solve either of these problems? I have tried also the CONT5 option since this draws the contours using Delaunay triangulation, which I hoped would solve the problem of the discontinuity mentioned previously. However this creates an almighty mess, as shown below:

Any suggestions for making pretty contour plots from sporadic data will be welcomed. The data is continuous in the X-coordinate but sporadically sampled in Y, with the attached data file consisting of 12 different Y-values. I have other data sets that need to be plotted in such a fashion where there are only 4 Y-values, so the mentioned problems are even worse in these cases.

Can you also provide the small macro producing these plots ?

The following is an example of how the TGraph2D is constructed and the subsequent draw command:

void plot_Ex_contour_40ca_208pb_115deg(){

 std::ifstream contourfile("40Ca_208Pb_39K_Ex_115deg.dat",std::ios::in);

  TGraph2D* contour = new TGraph2D();

  int pointno = 0;



      std::string line;



        TString lin(line);

        TObjArray* tokens = lin.Tokenize(TString("\t"));


        double E_over_Vb = ((TObjString*)tokens->At(0))->String().Atof();

        double Ex = ((TObjString*)tokens->At(1))->String().Atof();

        double dP_dEx = ((TObjString*)tokens->At(2))->String().Atof();






  TCanvas* c = new TCanvas("contour_canvas","contour_canvas");


  std::cout<<"g points = "<<contour->GetN()<<endl;


  contour->GetHistogram()->GetXaxis()->SetTitle("Ex (MeV)");
  contour->GetHistogram()->GetYaxis()->SetTitle("E / V_{B}");
  contour->GetHistogram()->GetZaxis()->SetTitle("dP / dE_{x} (MeV^{-1})");

  TH2D* contourhist = contour->GetHistogram();


  contour->Draw("CONT4Z"); // Or contour->Draw("TRI2Z"); OR contour->Draw("CONT5Z");
  // canvas->SetTheta(90);   // where TRI2 option used
  // canvas->SetPhi(0);                        // where TRI2 option used

With the root master your macro gives me the following output:

I’m assuming that plot was made using the CONT4Z option?

Is there any reason why this would be performing differently in root 5.34?

Would you mind showing me your output from the following data file:

32S_208Pb_31P_Ex_102deg.txt (16.8 KB)

On my machine this looks like this:

Yes it is the output of your macro. I did not change it.

Your new data set gives me:

The triangulation algorithm has changed in between.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.