Create a TGraph points with different colors

Hi @couet

I have seen the following solution to create a TGraph where each point has a different color.

However, in that example, the color of each marker/point depends on the order of the point.

I wonder how the macro needs to be modified so that I can pass a property, such as the energy of the particle, and then implement the logic at DrawCol( Double_t energy) to define the color that corresponds to each energy range.

I imagine the line

TExec *ex = new TExec("ex","DrawCol();")

would need to be updated?

On top of that, I would like to implement those methods inside a class, lets say A. I could extrapolate this example easily?

I.e., at the implementation of A::graphmulticol I could simply update TExec line to the following?

   TExec *ex = new TExec("ex","A::DrawCol();");

Perhaps I need to make the method static?

On the other hand, would not be handy that the TGraph would have a method that allows to change each point color?

TGraph::SetPointColor( Int_t n, Int_t color); // Sets point "n" to color "color"

ThankYou!

This macro is just a demonstration of principle. You will need to map a value onto a colormap. Putting it in a class you will not need TExec. I am looking at implementing a TScatter class inheriting from TGraph and doing that.

1 Like

Perhaps naming it TScatterGraph would make it clear it inherits from TGraph.

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