No color options for 2D histo

Hi guys,
somehow I can`t make the different types of 2D histos work (colz, box etc.). Every time I just get the default scatterplot with grey dots.

My code looks like this (I am using root in python):


2d_histo = rt.TH2F("","", 100, 0, 2500 , 100, 0, 2500)

for i in range(len(data)):
	2d_histo.Fill(data1[i], data2[i])


I have tried all different types but nothing changes.

Weird… that’s python but that should not be the problem. You see the scatter plot, so the Draw command is working. Your script cannot be run because the data are missing. Can you post a running script showing the problem ?

So for example this code:

import ROOT as rt
import numpy as np
from ROOT import *

data = np.random.normal(0, 2.5, size=(2, 10000))

c1 = rt.TCanvas("c1")
f = rt.TFile("2dhist.root", "RECREATE")


histo = rt.TH2F("","", 100, -10, 10 , 100, -10, 10)

for i in range(len(data[1])):
	histo.Fill(data[0][i], data[1][i])


Just gives me the grey scatterplot.

Your script as it is doesn’t give me any output. I made a C++ version of it which shows the color plot.

   auto c1 = new TCanvas("c1");
   auto f = new TFile("2dhist.root", "RECREATE");


   auto histo = new TH2F("","", 100, -10, 10 , 100, -10, 10);

   float px, py;
   for (Int_t i = 0; i < 25000; i++) {


@couet Maybe you missed “-i”: python -i

1 Like

Yes with “-i” I get:

So, it is fine.

Yes i just tried it and with -i I also get this output. But in the rootfile itself, when I open it via the TBrowser I only see the grey scatterplot.

When you save an histogram in a ROOT file you save the histogram data only not the drawing option. The Drawing option is specified when you Draw the histogram. In the browser you have a menu choice where you can set the drawing option.

OK I see, thank you!

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