TGraph2D with coloured line collapsed in 2D

Dear ROOT experts,

I am wondering if it’s possible to plot a TGraph2D in a “line” form in 2D, using a changing colour of the line as if it was the “Z-axis”.

Example: I have a set of (x,y,z).
I can draw them in 3D, with the option “P”, and I see a curve.
It would be great (if possible) to collapse this into a 2D (like a simple TGraph), where the colour of the line is a representation of the Z-component.
Something similar can be performed with a TH2F and “colz” option, but some nice features of TGraph are lost there (like the line width to better see the line).
I understand the ambiguity in the case we have 2 points with the same X,Y and different Z, but an option like “maximum of Z” or “minimum of Z” could be added in that case.

If possible, this would be a nice feature for visualization.

Best regards,
Andrea

The option TRI1 does this color mapping on Z

alos note that in the general case there no way to know how to connect the point to produce the lines you want.

Thanks for the fast feedback!

TRI1 works, but the plot is still 3D.

I understand the way to connect to points to produce the line is definitely not trivial. I was thinking naively to something like the natural ordering that can be obtained with “GetX()” (Y, Z) methods.
A simple workaround I did (but still using TH2F) is in the following:

graph is the TGraph2D

TH2F* myHisto = (TH2F*) graph->GetHistogram()->Clone(“myHisto”);
for (int i=0; iGetSize(); i++) {
myHisto->SetBinContent(i+1, 0);
}

for (int i=0; iGetN(); i++) {
myHisto->Fill( graph->GetX()[i], graph->GetY()[i], graph->GetZ()[i]);
}

myHisto->Draw(“colz”);

In that case that exist already simply use the option COLZ to Draw the TGraph2D

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