Draw scatterplot graph on top of 2D histogram

Hi, I’m new to Root, and I’m trying to draw a set of points ((x,y) coordinates in a .txt) on top (as in, in the same graph) of a 2D histogram (a TH2C I’ve managed to draw on a canvas, with “colz”). I’ve seen the TMultiGraph class, but from what I gather I don’t think it can be used with a TH2C.
How could I achieve this?

This is the code I have so far:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXLINES 65536

int prueba()
    FILE* fp;
    char buffer[1000];
    double x[MAXLINES];
    double y[MAXLINES];
    int counts[MAXLINES];
    size_t lines = 0;
    size_t i;

    // Open file in reading mode
    fp = fopen("anger-integral.txt", "r");
    // Check if the file has been opened
    if (NULL == fp) {
        printf("file can't be opened \n");
        return 1;
    // Read line by line and save the values in corresponding variables
    while (fgets(buffer, sizeof buffer, fp) != NULL) {
        if (sscanf(buffer, "%lf%lf%i",
                   &x[lines], &y[lines], &counts[lines]) == 3) {
    // Close the file

    // Histogram size and limits
    int binN = 256;
    int xmin = -1, xmax = 1;
    int ymin = -1, ymax = 1;

    // Create root canvas
    TCanvas* c_1 = new TCanvas("c_1","Llenado de campo", 1000,0, 1500,1500);
    // Create histogram
    TH2C* htwoD = new TH2C("Histograma","Llenado de campo", binN, xmin, xmax, binN, ymin, ymax);
    // Fill histogram with read data
    for (i = 0; i < lines; i++) {
    // Draw histogram to canvas
    return 0;

Thank you in advance.

ROOT Version: 6.26/10
Platform: Ubuntu 22.04
Compiler: Not Provided

Welcome to the ROOT forum.

You want something like the 2nd example here:


No, I want to draw the points themselves, not the coordinates in text. I want to draw the points (as crosses for example) at the coordinates loaded from a .txt file (different from the .txt source of the histogram data). Something like the following (I’ve painted the crosses manually to illustrate):

I see. Put the (x,y) values in a TGraph and draw it on top of the color plot: