Scatter plot with points color based on palette

Hi everyone,

I was wondering how I could create points in a scatter plot (x,y) that is based on the value of some intensity for each point. Basically, I have this so far:

double x[n], y[n];
int intensity[n];
TGraph *g = new TGraph(n,x,y);

I simply want to include the values found in intensity[] on my plot with a color scale from TPalette for each point. Most of what I found is good for the TH2 object but I need to stick to TGraph.

Thanks :slight_smile:

It seems to me that you either want a TGraph2D or you are interested in TGraphPainter -> Colors automatically picked in palette.

Thanks for the suggestion but the problem with TGraph2D is that it gives me a 3D visualization while I simply want a (x,y) plot with my 3rd dimension (the intensity) being expressed with the color of the marker from the TPalette.

Is there a way to do that?

A TGraph2D can be also drawn with any options valid to draw a 2D histogram (like COL , SURF , LEGO , CONT etc…).

I have already try these options with TGraph2D but they do not produce the plots I am looking for as it seems to be producing some sort of binning. I only want the n points to be shown on that color palette scale.

My code is:

void images()
	TCanvas *c1 = new TCanvas("c1","c1",0,0,800,850);
        // drawing a circle
	double x[360], y[360];
	for (int i = 0; i < 360; ++i)
	TGraph* gr = new TGraph(360,x,y);

    double x_image[17] = {-0.086,-0.043,-0.173,-0.1299,-0.086,-0.043,-0.173,-0.1299,-0.086,-0.173,-0.1299,-0.216,-0.173,-0.1299,-0.2598,-0.216,-0.173};
    double y_image[17] = {0.4,0.425,0.4,0.425,0.45,0.475,0.45,0.475,0.5,0.6,0.625,0.625,0.65,0.675,0.65,0.675,0.7};
    double npe_image[17] = {7395,8678,553,8441,8864,8668,1944,4961,5319,5915,8781,4739,9005,5322,460,2795,881};

    TGraph *g = new TGraph(17,x_image,y_image);
    g->Draw("same p");

which produces the plot:

I want the tiny points in the circle to be colored based on the value of npe_image[i] with the color palette. Maybe I should have started with this.

In fact, it seems that it is possible with TGraph2D according to the thread (that I seem to have missed) here:

So thanks again Wil :slight_smile:

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