Home | News | Documentation | Download

Drawing TH2 contours, incorrect (?) regions being shaded

Hi -

A query about TH2 contour drawing options and shading.

First off, I don’t think this is a bug. I think it is a case of me not fully understanding how to accomplish what I am trying to do.

First let me show you a figure drawn with “COLZ” drawing options, so you can see what the data looks like.

As you can see this is quite a low resolution figure. The white regions are zero by default, but I have set them to std::numeric_limits<double>::infinity(). (Without this additional lines are drawn with “cont3” which should not be there.)

I have set my contours using the following

double clevels[2] = {min + 0.23, min + 4.61};
hist->SetContour(2, clevels);

This is what it looks like with cont3same.

I then tried to draw these with regions instead of lines, using cont. This was the result.

It isn’t what I was aiming to achieve, however it probably is what you would expect.

The objective really is to do this… (My “artist” impression with GIMP.)

I’m not sure how to proceed here… One possible solution has been suggested - to convert the lines to TH1 objects and draw filled histograms or TGraph objects on top of each other… but I’m not sure that’s the easiest approach. Perhaps there is some way to add new line segments to the contour lines to extend them off the edge of the figure and produce the desired result?

Hmm, difficult to help: our main graphics expert is out of office still for more than a month - maybe @linev has an idea what could be done here?

@Birdsall
It would be nice if you can post your ROOT macro or ROOT files with stored TCanvas - it would be much easier to debug problem

Not a simple request, unless you know an easy way?

Let’s start with the data. I can send you this in a root macro format.

Here is the output of h_new_clone.C

{
//========= Macro generated from object: h_new/
//========= by ROOT version6.18/04
   
   TH2D *h_new__1 = new TH2D("h_new__1","",25,0,0.2,25,0,1.2);
   h_new__1->SetBinContent(28,inf);
   h_new__1->SetBinContent(29,inf);
   h_new__1->SetBinContent(30,inf);
   h_new__1->SetBinContent(31,inf);
   h_new__1->SetBinContent(32,inf);
   h_new__1->SetBinContent(33,inf);
   h_new__1->SetBinContent(34,inf);
   h_new__1->SetBinContent(35,inf);
   h_new__1->SetBinContent(36,inf);
   h_new__1->SetBinContent(37,11.3188);
   h_new__1->SetBinContent(38,11.3188);
   h_new__1->SetBinContent(39,11.3188);
   h_new__1->SetBinContent(40,11.3188);
   h_new__1->SetBinContent(41,11.3188);
   h_new__1->SetBinContent(42,11.3188);
   h_new__1->SetBinContent(43,11.3188);
   h_new__1->SetBinContent(44,11.3188);
   h_new__1->SetBinContent(45,11.3188);
   h_new__1->SetBinContent(46,11.3188);
   h_new__1->SetBinContent(47,11.3188);
   h_new__1->SetBinContent(48,11.3188);
   h_new__1->SetBinContent(49,11.3188);
   h_new__1->SetBinContent(50,11.3188);
   h_new__1->SetBinContent(51,11.3188);
   h_new__1->SetBinContent(52,11.3188);
   h_new__1->SetBinContent(55,inf);
   h_new__1->SetBinContent(56,inf);
   h_new__1->SetBinContent(57,11.3188);
   h_new__1->SetBinContent(58,11.3188);
   h_new__1->SetBinContent(59,11.3188);
   h_new__1->SetBinContent(60,11.3188);
   h_new__1->SetBinContent(61,11.3188);
   h_new__1->SetBinContent(62,11.0449);
   h_new__1->SetBinContent(63,11.0449);
   h_new__1->SetBinContent(64,11.0449);
   h_new__1->SetBinContent(65,11.0449);
   h_new__1->SetBinContent(66,11.0449);
   h_new__1->SetBinContent(67,10.7758);
   h_new__1->SetBinContent(68,10.7758);
   h_new__1->SetBinContent(69,10.7758);
   h_new__1->SetBinContent(70,10.7758);
   h_new__1->SetBinContent(71,10.7758);
   h_new__1->SetBinContent(72,10.5114);
   h_new__1->SetBinContent(73,10.5114);
   h_new__1->SetBinContent(74,10.5114);
   h_new__1->SetBinContent(75,10.5114);
   h_new__1->SetBinContent(76,10.5114);
   h_new__1->SetBinContent(77,10.2515);
   h_new__1->SetBinContent(78,10.2515);
   h_new__1->SetBinContent(79,10.2515);
   h_new__1->SetBinContent(82,inf);
   h_new__1->SetBinContent(83,11.3188);
   h_new__1->SetBinContent(84,11.5978);
   h_new__1->SetBinContent(85,11.0449);
   h_new__1->SetBinContent(86,11.0449);
   h_new__1->SetBinContent(87,10.7758);
   h_new__1->SetBinContent(88,10.7758);
   h_new__1->SetBinContent(89,10.7758);
   h_new__1->SetBinContent(90,10.5114);
   h_new__1->SetBinContent(91,10.5114);
   h_new__1->SetBinContent(92,10.2515);
   h_new__1->SetBinContent(93,10.2515);
   h_new__1->SetBinContent(94,9.99637);
   h_new__1->SetBinContent(95,9.99637);
   h_new__1->SetBinContent(96,9.74583);
   h_new__1->SetBinContent(97,9.74583);
   h_new__1->SetBinContent(98,9.53081);
   h_new__1->SetBinContent(99,9.49984);
   h_new__1->SetBinContent(100,9.49984);
   h_new__1->SetBinContent(101,9.25827);
   h_new__1->SetBinContent(102,9.25827);
   h_new__1->SetBinContent(103,9.02083);
   h_new__1->SetBinContent(104,9.02083);
   h_new__1->SetBinContent(105,8.78776);
   h_new__1->SetBinContent(106,8.78776);
   h_new__1->SetBinContent(109,inf);
   h_new__1->SetBinContent(110,inf);
   h_new__1->SetBinContent(111,11.0449);
   h_new__1->SetBinContent(112,10.7758);
   h_new__1->SetBinContent(113,10.5114);
   h_new__1->SetBinContent(114,10.5114);
   h_new__1->SetBinContent(115,10.2515);
   h_new__1->SetBinContent(116,9.99637);
   h_new__1->SetBinContent(117,9.74583);
   h_new__1->SetBinContent(118,9.49984);
   h_new__1->SetBinContent(119,9.3193);
   h_new__1->SetBinContent(120,9.25827);
   h_new__1->SetBinContent(121,9.02083);
   h_new__1->SetBinContent(122,8.78776);
   h_new__1->SetBinContent(123,8.55899);
   h_new__1->SetBinContent(124,8.33584);
   h_new__1->SetBinContent(125,8.33446);
   h_new__1->SetBinContent(126,8.1141);
   h_new__1->SetBinContent(127,7.89785);
   h_new__1->SetBinContent(128,7.68556);
   h_new__1->SetBinContent(129,7.47711);
   h_new__1->SetBinContent(130,7.3532);
   h_new__1->SetBinContent(131,7.2726);
   h_new__1->SetBinContent(132,7.07197);
   h_new__1->SetBinContent(133,6.87518);
   h_new__1->SetBinContent(136,11.3188);
   h_new__1->SetBinContent(137,11.0449);
   h_new__1->SetBinContent(138,10.7758);
   h_new__1->SetBinContent(139,10.5114);
   h_new__1->SetBinContent(140,9.99637);
   h_new__1->SetBinContent(141,9.74583);
   h_new__1->SetBinContent(142,9.49984);
   h_new__1->SetBinContent(143,9.10218);
   h_new__1->SetBinContent(144,8.78776);
   h_new__1->SetBinContent(145,8.55899);
   h_new__1->SetBinContent(146,8.33446);
   h_new__1->SetBinContent(147,7.89785);
   h_new__1->SetBinContent(148,7.68556);
   h_new__1->SetBinContent(149,7.47711);
   h_new__1->SetBinContent(150,7.21952);
   h_new__1->SetBinContent(151,6.87518);
   h_new__1->SetBinContent(152,6.68217);
   h_new__1->SetBinContent(153,6.49288);
   h_new__1->SetBinContent(154,6.12685);
   h_new__1->SetBinContent(155,5.94682);
   h_new__1->SetBinContent(156,5.77191);
   h_new__1->SetBinContent(157,5.47514);
   h_new__1->SetBinContent(158,5.26774);
   h_new__1->SetBinContent(159,5.10636);
   h_new__1->SetBinContent(160,4.86795);
   h_new__1->SetBinContent(163,39.7671);
   h_new__1->SetBinContent(164,10.7758);
   h_new__1->SetBinContent(165,10.2515);
   h_new__1->SetBinContent(166,9.99637);
   h_new__1->SetBinContent(167,9.49984);
   h_new__1->SetBinContent(168,9.02083);
   h_new__1->SetBinContent(169,8.55899);
   h_new__1->SetBinContent(170,8.1141);
   h_new__1->SetBinContent(171,7.71773);
   h_new__1->SetBinContent(172,7.47711);
   h_new__1->SetBinContent(173,7.07197);
   h_new__1->SetBinContent(174,6.68217);
   h_new__1->SetBinContent(175,6.30726);
   h_new__1->SetBinContent(176,5.94682);
   h_new__1->SetBinContent(177,5.60047);
   h_new__1->SetBinContent(178,5.28015);
   h_new__1->SetBinContent(179,5.00627);
   h_new__1->SetBinContent(180,4.77754);
   h_new__1->SetBinContent(181,4.49338);
   h_new__1->SetBinContent(182,4.20581);
   h_new__1->SetBinContent(183,3.93042);
   h_new__1->SetBinContent(184,3.66691);
   h_new__1->SetBinContent(185,3.4149);
   h_new__1->SetBinContent(186,3.17406);
   h_new__1->SetBinContent(187,2.94419);
   h_new__1->SetBinContent(190,inf);
   h_new__1->SetBinContent(191,10.5114);
   h_new__1->SetBinContent(192,9.99637);
   h_new__1->SetBinContent(193,9.25827);
   h_new__1->SetBinContent(194,8.78776);
   h_new__1->SetBinContent(195,8.1141);
   h_new__1->SetBinContent(196,7.68556);
   h_new__1->SetBinContent(197,7.07197);
   h_new__1->SetBinContent(198,6.68217);
   h_new__1->SetBinContent(199,6.12526);
   h_new__1->SetBinContent(200,5.77191);
   h_new__1->SetBinContent(201,5.26774);
   h_new__1->SetBinContent(202,4.86795);
   h_new__1->SetBinContent(203,4.49338);
   h_new__1->SetBinContent(204,4.07321);
   h_new__1->SetBinContent(205,3.7972);
   h_new__1->SetBinContent(206,3.4149);
   h_new__1->SetBinContent(207,3.09659);
   h_new__1->SetBinContent(208,2.83329);
   h_new__1->SetBinContent(209,2.51631);
   h_new__1->SetBinContent(210,2.26489);
   h_new__1->SetBinContent(211,2.03861);
   h_new__1->SetBinContent(212,1.78047);
   h_new__1->SetBinContent(213,1.56403);
   h_new__1->SetBinContent(214,1.39617);
   h_new__1->SetBinContent(217,11.0449);
   h_new__1->SetBinContent(218,10.2515);
   h_new__1->SetBinContent(219,9.49984);
   h_new__1->SetBinContent(220,8.78776);
   h_new__1->SetBinContent(221,7.89785);
   h_new__1->SetBinContent(222,7.2726);
   h_new__1->SetBinContent(223,6.68217);
   h_new__1->SetBinContent(224,5.98803);
   h_new__1->SetBinContent(225,5.43244);
   h_new__1->SetBinContent(226,4.94828);
   h_new__1->SetBinContent(227,4.36102);
   h_new__1->SetBinContent(228,3.93042);
   h_new__1->SetBinContent(229,3.50282);
   h_new__1->SetBinContent(230,3.05777);
   h_new__1->SetBinContent(231,2.72503);
   h_new__1->SetBinContent(232,2.3178);
   h_new__1->SetBinContent(233,2.03861);
   h_new__1->SetBinContent(234,1.6991);
   h_new__1->SetBinContent(235,1.46238);
   h_new__1->SetBinContent(236,1.19135);
   h_new__1->SetBinContent(237,0.972889);
   h_new__1->SetBinContent(238,0.785189);
   h_new__1->SetBinContent(239,0.595963);
   h_new__1->SetBinContent(240,0.471906);
   h_new__1->SetBinContent(241,0.331654);
   h_new__1->SetBinContent(244,12.7818);
   h_new__1->SetBinContent(245,9.99637);
   h_new__1->SetBinContent(246,9.02083);
   h_new__1->SetBinContent(247,8.1141);
   h_new__1->SetBinContent(248,7.09672);
   h_new__1->SetBinContent(249,6.30726);
   h_new__1->SetBinContent(250,5.60047);
   h_new__1->SetBinContent(251,4.94828);
   h_new__1->SetBinContent(252,4.26358);
   h_new__1->SetBinContent(253,3.66691);
   h_new__1->SetBinContent(254,3.17406);
   h_new__1->SetBinContent(255,2.65462);
   h_new__1->SetBinContent(256,2.2223);
   h_new__1->SetBinContent(257,1.85902);
   h_new__1->SetBinContent(258,1.46864);
   h_new__1->SetBinContent(259,1.19135);
   h_new__1->SetBinContent(260,0.891341);
   h_new__1->SetBinContent(261,0.673731);
   h_new__1->SetBinContent(262,0.471906);
   h_new__1->SetBinContent(263,0.301689);
   h_new__1->SetBinContent(264,0.193267);
   h_new__1->SetBinContent(265,0.0938942);
   h_new__1->SetBinContent(266,0.0309399);
   h_new__1->SetBinContent(267,0.00479205);
   h_new__1->SetBinContent(268,1.02001e-05);
   h_new__1->SetBinContent(271,10.7758);
   h_new__1->SetBinContent(272,9.49984);
   h_new__1->SetBinContent(273,8.33446);
   h_new__1->SetBinContent(274,7.2726);
   h_new__1->SetBinContent(275,6.30726);
   h_new__1->SetBinContent(276,5.43244);
   h_new__1->SetBinContent(277,4.58617);
   h_new__1->SetBinContent(278,3.7972);
   h_new__1->SetBinContent(279,3.17406);
   h_new__1->SetBinContent(280,2.55052);
   h_new__1->SetBinContent(281,2.03861);
   h_new__1->SetBinContent(282,1.5855);
   h_new__1->SetBinContent(283,1.19135);
   h_new__1->SetBinContent(284,0.844958);
   h_new__1->SetBinContent(285,0.595249);
   h_new__1->SetBinContent(286,0.364292);
   h_new__1->SetBinContent(287,0.193267);
   h_new__1->SetBinContent(288,0.0834577);
   h_new__1->SetBinContent(289,0.0224912);
   h_new__1->SetBinContent(290,1.02001e-05);
   h_new__1->SetBinContent(291,1.02001e-05);
   h_new__1->SetBinContent(292,1.02001e-05);
   h_new__1->SetBinContent(293,1.02001e-05);
   h_new__1->SetBinContent(294,1.02001e-05);
   h_new__1->SetBinContent(295,0.00598794);
   h_new__1->SetBinContent(298,11.1547);
   h_new__1->SetBinContent(299,9.25827);
   h_new__1->SetBinContent(300,7.89785);
   h_new__1->SetBinContent(301,6.49757);
   h_new__1->SetBinContent(302,5.43244);
   h_new__1->SetBinContent(303,4.49338);
   h_new__1->SetBinContent(304,3.53952);
   h_new__1->SetBinContent(305,2.83329);
   h_new__1->SetBinContent(306,2.12926);
   h_new__1->SetBinContent(307,1.5855);
   h_new__1->SetBinContent(308,1.12734);
   h_new__1->SetBinContent(309,0.735075);
   h_new__1->SetBinContent(310,0.43423);
   h_new__1->SetBinContent(311,0.217825);
   h_new__1->SetBinContent(312,0.0785287);
   h_new__1->SetBinContent(313,0.0098416);
   h_new__1->SetBinContent(314,1.02001e-05);
   h_new__1->SetBinContent(315,1.02001e-05);
   h_new__1->SetBinContent(316,1.02001e-05);
   h_new__1->SetBinContent(317,0.000816087);
   h_new__1->SetBinContent(318,0.0309433);
   h_new__1->SetBinContent(319,0.102757);
   h_new__1->SetBinContent(320,0.21337);
   h_new__1->SetBinContent(321,0.362706);
   h_new__1->SetBinContent(322,0.555453);
   h_new__1->SetBinContent(325,10.5114);
   h_new__1->SetBinContent(326,8.78776);
   h_new__1->SetBinContent(327,7.2726);
   h_new__1->SetBinContent(328,5.77191);
   h_new__1->SetBinContent(329,4.64183);
   h_new__1->SetBinContent(330,3.53951);
   h_new__1->SetBinContent(331,2.61938);
   h_new__1->SetBinContent(332,1.87405);
   h_new__1->SetBinContent(333,1.27325);
   h_new__1->SetBinContent(334,0.791805);
   h_new__1->SetBinContent(335,0.43423);
   h_new__1->SetBinContent(336,0.193267);
   h_new__1->SetBinContent(337,0.0462682);
   h_new__1->SetBinContent(338,1.02001e-05);
   h_new__1->SetBinContent(339,1.02001e-05);
   h_new__1->SetBinContent(340,1.02001e-05);
   h_new__1->SetBinContent(341,0.0104774);
   h_new__1->SetBinContent(342,0.0743327);
   h_new__1->SetBinContent(343,0.201026);
   h_new__1->SetBinContent(344,0.387108);
   h_new__1->SetBinContent(345,0.621169);
   h_new__1->SetBinContent(346,0.906476);
   h_new__1->SetBinContent(347,1.25475);
   h_new__1->SetBinContent(348,1.63308);
   h_new__1->SetBinContent(349,2.06012);
   h_new__1->SetBinContent(352,12.4926);
   h_new__1->SetBinContent(353,8.33446);
   h_new__1->SetBinContent(354,6.52017);
   h_new__1->SetBinContent(355,5.10636);
   h_new__1->SetBinContent(356,3.7972);
   h_new__1->SetBinContent(357,2.69835);
   h_new__1->SetBinContent(358,1.78964);
   h_new__1->SetBinContent(359,1.12734);
   h_new__1->SetBinContent(360,0.616908);
   h_new__1->SetBinContent(361,0.271459);
   h_new__1->SetBinContent(362,0.0644004);
   h_new__1->SetBinContent(363,1.02001e-05);
   h_new__1->SetBinContent(364,1.02001e-05);
   h_new__1->SetBinContent(365,0.000816087);
   h_new__1->SetBinContent(366,0.051127);
   h_new__1->SetBinContent(367,0.192095);
   h_new__1->SetBinContent(368,0.415544);
   h_new__1->SetBinContent(369,0.71233);
   h_new__1->SetBinContent(370,1.07675);
   h_new__1->SetBinContent(371,1.5073);
   h_new__1->SetBinContent(372,2.01006);
   h_new__1->SetBinContent(373,2.56384);
   h_new__1->SetBinContent(374,3.1904);
   h_new__1->SetBinContent(375,3.84353);
   h_new__1->SetBinContent(376,4.56348);
   h_new__1->SetBinContent(379,10.2515);
   h_new__1->SetBinContent(380,7.89785);
   h_new__1->SetBinContent(381,5.94682);
   h_new__1->SetBinContent(382,4.34805);
   h_new__1->SetBinContent(383,2.94419);
   h_new__1->SetBinContent(384,1.90098);
   h_new__1->SetBinContent(385,1.11901);
   h_new__1->SetBinContent(386,0.538086);
   h_new__1->SetBinContent(387,0.170889);
   h_new__1->SetBinContent(388,0.0155567);
   h_new__1->SetBinContent(389,1.02001e-05);
   h_new__1->SetBinContent(390,0.000816087);
   h_new__1->SetBinContent(391,0.0743327);
   h_new__1->SetBinContent(392,0.258056);
   h_new__1->SetBinContent(393,0.563576);
   h_new__1->SetBinContent(394,0.951226);
   h_new__1->SetBinContent(395,1.45048);
   h_new__1->SetBinContent(396,2.03014);
   h_new__1->SetBinContent(397,2.69419);
   h_new__1->SetBinContent(398,3.43164);
   h_new__1->SetBinContent(399,4.23625);
   h_new__1->SetBinContent(400,5.11417);
   h_new__1->SetBinContent(401,6.04077);
   h_new__1->SetBinContent(402,7.02801);
   h_new__1->SetBinContent(403,8.05863);
   h_new__1->SetBinContent(406,9.99637);
   h_new__1->SetBinContent(407,7.47711);
   h_new__1->SetBinContent(408,5.26774);
   h_new__1->SetBinContent(409,3.53951);
   h_new__1->SetBinContent(410,2.2223);
   h_new__1->SetBinContent(411,1.25747);
   h_new__1->SetBinContent(412,0.552428);
   h_new__1->SetBinContent(413,0.149157);
   h_new__1->SetBinContent(414,0.0023666);
   h_new__1->SetBinContent(415,1.02001e-05);
   h_new__1->SetBinContent(416,0.0399434);
   h_new__1->SetBinContent(417,0.218934);
   h_new__1->SetBinContent(418,0.555453);
   h_new__1->SetBinContent(419,1.03124);
   h_new__1->SetBinContent(420,1.62314);
   h_new__1->SetBinContent(421,2.33239);
   h_new__1->SetBinContent(422,3.15434);
   h_new__1->SetBinContent(423,4.07704);
   h_new__1->SetBinContent(424,5.06952);
   h_new__1->SetBinContent(425,6.1562);
   h_new__1->SetBinContent(426,7.31278);
   h_new__1->SetBinContent(427,8.53755);
   h_new__1->SetBinContent(428,9.8104);
   h_new__1->SetBinContent(429,11.1637);
   h_new__1->SetBinContent(430,inf);
   h_new__1->SetBinContent(433,9.90719);
   h_new__1->SetBinContent(434,6.90085);
   h_new__1->SetBinContent(435,4.64183);
   h_new__1->SetBinContent(436,2.85029);
   h_new__1->SetBinContent(437,1.56403);
   h_new__1->SetBinContent(438,0.686565);
   h_new__1->SetBinContent(439,0.177182);
   h_new__1->SetBinContent(440,0.0021625);
   h_new__1->SetBinContent(441,1.02001e-05);
   h_new__1->SetBinContent(442,0.0888306);
   h_new__1->SetBinContent(443,0.387108);
   h_new__1->SetBinContent(444,0.870317);
   h_new__1->SetBinContent(445,1.53272);
   h_new__1->SetBinContent(446,2.33239);
   h_new__1->SetBinContent(447,3.28607);
   h_new__1->SetBinContent(448,4.36517);
   h_new__1->SetBinContent(449,5.54774);
   h_new__1->SetBinContent(450,6.82584);
   h_new__1->SetBinContent(451,8.20321);
   h_new__1->SetBinContent(452,9.6654);
   h_new__1->SetBinContent(453,11.2176);
   h_new__1->SetBinContent(454,inf);
   h_new__1->SetBinContent(455,inf);
   h_new__1->SetBinContent(456,inf);
   h_new__1->SetBinContent(457,inf);
   h_new__1->SetBinContent(460,9.74583);
   h_new__1->SetBinContent(461,6.49288);
   h_new__1->SetBinContent(462,4.06661);
   h_new__1->SetBinContent(463,2.2223);
   h_new__1->SetBinContent(464,1.00552);
   h_new__1->SetBinContent(465,0.300687);
   h_new__1->SetBinContent(466,0.0098416);
   h_new__1->SetBinContent(467,1.02001e-05);
   h_new__1->SetBinContent(468,0.135265);
   h_new__1->SetBinContent(469,0.514554);
   h_new__1->SetBinContent(470,1.14839);
   h_new__1->SetBinContent(471,1.98296);
   h_new__1->SetBinContent(472,3.0057);
   h_new__1->SetBinContent(473,4.20548);
   h_new__1->SetBinContent(474,5.53352);
   h_new__1->SetBinContent(475,7.00958);
   h_new__1->SetBinContent(476,8.59815);
   h_new__1->SetBinContent(477,10.2743);
   h_new__1->SetBinContent(478,13.6533);
   h_new__1->SetBinContent(479,inf);
   h_new__1->SetBinContent(480,inf);
   h_new__1->SetBinContent(481,inf);
   h_new__1->SetBinContent(482,inf);
   h_new__1->SetBinContent(483,inf);
   h_new__1->SetBinContent(484,inf);
   h_new__1->SetBinContent(487,9.49984);
   h_new__1->SetBinContent(488,5.94682);
   h_new__1->SetBinContent(489,3.4149);
   h_new__1->SetBinContent(490,1.63399);
   h_new__1->SetBinContent(491,0.552755);
   h_new__1->SetBinContent(492,0.0644004);
   h_new__1->SetBinContent(493,1.02001e-05);
   h_new__1->SetBinContent(494,0.118426);
   h_new__1->SetBinContent(495,0.571851);
   h_new__1->SetBinContent(496,1.31414);
   h_new__1->SetBinContent(497,2.32485);
   h_new__1->SetBinContent(498,3.56717);
   h_new__1->SetBinContent(499,4.99985);
   h_new__1->SetBinContent(500,6.61962);
   h_new__1->SetBinContent(501,8.38286);
   h_new__1->SetBinContent(502,10.2743);
   h_new__1->SetBinContent(503,inf);
   h_new__1->SetBinContent(504,inf);
   h_new__1->SetBinContent(505,inf);
   h_new__1->SetBinContent(506,inf);
   h_new__1->SetBinContent(507,inf);
   h_new__1->SetBinContent(508,inf);
   h_new__1->SetBinContent(509,inf);
   h_new__1->SetBinContent(510,inf);
   h_new__1->SetBinContent(511,inf);
   h_new__1->SetBinContent(514,9.25827);
   h_new__1->SetBinContent(515,5.43244);
   h_new__1->SetBinContent(516,2.83329);
   h_new__1->SetBinContent(517,1.12734);
   h_new__1->SetBinContent(518,0.243955);
   h_new__1->SetBinContent(519,1.02001e-05);
   h_new__1->SetBinContent(520,0.0663162);
   h_new__1->SetBinContent(521,0.510324);
   h_new__1->SetBinContent(522,1.34903);
   h_new__1->SetBinContent(523,2.49474);
   h_new__1->SetBinContent(524,3.9352);
   h_new__1->SetBinContent(525,5.61901);
   h_new__1->SetBinContent(526,7.49896);
   h_new__1->SetBinContent(527,9.56812);
   h_new__1->SetBinContent(528,12.6609);
   h_new__1->SetBinContent(529,inf);
   h_new__1->SetBinContent(530,inf);
   h_new__1->SetBinContent(531,inf);
   h_new__1->SetBinContent(532,inf);
   h_new__1->SetBinContent(533,inf);
   h_new__1->SetBinContent(534,inf);
   h_new__1->SetBinContent(535,inf);
   h_new__1->SetBinContent(536,inf);
   h_new__1->SetBinContent(537,inf);
   h_new__1->SetBinContent(538,inf);
   h_new__1->SetBinContent(541,9.02083);
   h_new__1->SetBinContent(542,4.94828);
   h_new__1->SetBinContent(543,2.3178);
   h_new__1->SetBinContent(544,0.712095);
   h_new__1->SetBinContent(545,0.0462682);
   h_new__1->SetBinContent(546,0.00598794);
   h_new__1->SetBinContent(547,0.35925);
   h_new__1->SetBinContent(548,1.20852);
   h_new__1->SetBinContent(549,2.45994);
   h_new__1->SetBinContent(550,4.07704);
   h_new__1->SetBinContent(551,5.98325);
   h_new__1->SetBinContent(552,8.13755);
   h_new__1->SetBinContent(553,10.5012);
   h_new__1->SetBinContent(554,inf);
   h_new__1->SetBinContent(555,inf);
   h_new__1->SetBinContent(556,inf);
   h_new__1->SetBinContent(557,inf);
   h_new__1->SetBinContent(558,inf);
   h_new__1->SetBinContent(559,inf);
   h_new__1->SetBinContent(560,inf);
   h_new__1->SetBinContent(561,inf);
   h_new__1->SetBinContent(562,inf);
   h_new__1->SetBinContent(563,inf);
   h_new__1->SetBinContent(564,inf);
   h_new__1->SetBinContent(565,inf);
   h_new__1->SetBinContent(568,8.78776);
   h_new__1->SetBinContent(569,4.49338);
   h_new__1->SetBinContent(570,1.78047);
   h_new__1->SetBinContent(571,0.369897);
   h_new__1->SetBinContent(572,1.02001e-05);
   h_new__1->SetBinContent(573,0.153308);
   h_new__1->SetBinContent(574,0.906476);
   h_new__1->SetBinContent(575,2.19526);
   h_new__1->SetBinContent(576,3.9352);
   h_new__1->SetBinContent(577,6.02426);
   h_new__1->SetBinContent(578,8.44091);
   h_new__1->SetBinContent(579,11.0929);
   h_new__1->SetBinContent(580,inf);
   h_new__1->SetBinContent(581,inf);
   h_new__1->SetBinContent(582,inf);
   h_new__1->SetBinContent(583,inf);
   h_new__1->SetBinContent(584,inf);
   h_new__1->SetBinContent(585,inf);
   h_new__1->SetBinContent(586,inf);
   h_new__1->SetBinContent(587,inf);
   h_new__1->SetBinContent(588,inf);
   h_new__1->SetBinContent(589,inf);
   h_new__1->SetBinContent(590,inf);
   h_new__1->SetBinContent(591,inf);
   h_new__1->SetBinContent(592,inf);
   h_new__1->SetBinContent(595,8.55899);
   h_new__1->SetBinContent(596,3.98746);
   h_new__1->SetBinContent(597,1.32574);
   h_new__1->SetBinContent(598,0.149157);
   h_new__1->SetBinContent(599,0.00598794);
   h_new__1->SetBinContent(600,0.506712);
   h_new__1->SetBinContent(601,1.70579);
   h_new__1->SetBinContent(602,3.48167);
   h_new__1->SetBinContent(603,5.73956);
   h_new__1->SetBinContent(604,8.37649);
   h_new__1->SetBinContent(605,11.4111);
   h_new__1->SetBinContent(606,inf);
   h_new__1->SetBinContent(607,inf);
   h_new__1->SetBinContent(608,inf);
   h_new__1->SetBinContent(609,inf);
   h_new__1->SetBinContent(610,inf);
   h_new__1->SetBinContent(611,inf);
   h_new__1->SetBinContent(612,inf);
   h_new__1->SetBinContent(613,inf);
   h_new__1->SetBinContent(614,inf);
   h_new__1->SetBinContent(615,inf);
   h_new__1->SetBinContent(616,inf);
   h_new__1->SetBinContent(617,inf);
   h_new__1->SetBinContent(618,inf);
   h_new__1->SetBinContent(619,inf);
   h_new__1->SetBinContent(622,8.33446);
   h_new__1->SetBinContent(623,3.53951);
   h_new__1->SetBinContent(624,0.947417);
   h_new__1->SetBinContent(625,0.0214621);
   h_new__1->SetBinContent(626,0.135265);
   h_new__1->SetBinContent(627,1.07484);
   h_new__1->SetBinContent(628,2.77073);
   h_new__1->SetBinContent(629,5.09784);
   h_new__1->SetBinContent(630,7.90194);
   h_new__1->SetBinContent(631,11.0929);
   h_new__1->SetBinContent(632,inf);
   h_new__1->SetBinContent(633,inf);
   h_new__1->SetBinContent(634,inf);
   h_new__1->SetBinContent(635,inf);
   h_new__1->SetBinContent(636,inf);
   h_new__1->SetBinContent(637,inf);
   h_new__1->SetBinContent(638,inf);
   h_new__1->SetBinContent(639,inf);
   h_new__1->SetBinContent(640,inf);
   h_new__1->SetBinContent(641,inf);
   h_new__1->SetBinContent(642,inf);
   h_new__1->SetBinContent(643,inf);
   h_new__1->SetBinContent(644,inf);
   h_new__1->SetBinContent(645,inf);
   h_new__1->SetBinContent(646,inf);
   h_new__1->SetBinContent(649,7.89785);
   h_new__1->SetBinContent(650,3.05777);
   h_new__1->SetBinContent(651,0.595963);
   h_new__1->SetBinContent(652,1.02001e-05);
   h_new__1->SetBinContent(653,0.416152);
   h_new__1->SetBinContent(654,1.86033);
   h_new__1->SetBinContent(655,4.11393);
   h_new__1->SetBinContent(656,7.00958);
   h_new__1->SetBinContent(657,10.3978);
   h_new__1->SetBinContent(658,inf);
   h_new__1->SetBinContent(659,inf);
   h_new__1->SetBinContent(660,inf);
   h_new__1->SetBinContent(661,inf);
   h_new__1->SetBinContent(662,inf);
   h_new__1->SetBinContent(663,inf);
   h_new__1->SetBinContent(664,inf);
   h_new__1->SetBinContent(665,inf);
   h_new__1->SetBinContent(666,inf);
   h_new__1->SetBinContent(667,inf);
   h_new__1->SetBinContent(668,inf);
   h_new__1->SetBinContent(669,inf);
   h_new__1->SetBinContent(670,inf);
   h_new__1->SetBinContent(671,inf);
   h_new__1->SetBinContent(672,inf);
   h_new__1->SetBinContent(673,inf);
   h_new__1->SetBinContent(676,7.68556);
   h_new__1->SetBinContent(677,2.61938);
   h_new__1->SetBinContent(678,0.333092);
   h_new__1->SetBinContent(679,0.0161991);
   h_new__1->SetBinContent(680,0.881268);
   h_new__1->SetBinContent(681,2.87094);
   h_new__1->SetBinContent(682,5.72125);
   h_new__1->SetBinContent(683,9.20933);
   h_new__1->SetBinContent(684,inf);
   h_new__1->SetBinContent(685,inf);
   h_new__1->SetBinContent(686,inf);
   h_new__1->SetBinContent(687,inf);
   h_new__1->SetBinContent(688,inf);
   h_new__1->SetBinContent(689,inf);
   h_new__1->SetBinContent(690,inf);
   h_new__1->SetBinContent(691,inf);
   h_new__1->SetBinContent(692,inf);
   h_new__1->SetBinContent(693,inf);
   h_new__1->SetBinContent(694,inf);
   h_new__1->SetBinContent(695,inf);
   h_new__1->SetBinContent(696,inf);
   h_new__1->SetBinContent(697,inf);
   h_new__1->SetBinContent(698,inf);
   h_new__1->SetBinContent(699,inf);
   h_new__1->SetBinContent(700,inf);
   h_new__1->SetBinContent(703,1.02001e-05);
   h_new__1->SetBinContent(704,1.02001e-05);
   h_new__1->SetBinContent(705,1.02001e-05);
   h_new__1->SetBinContent(706,0.139146);
   h_new__1->SetBinContent(707,1.53272);
   h_new__1->SetBinContent(708,4.10263);
   h_new__1->SetBinContent(709,7.57564);
   h_new__1->SetBinContent(710,12.3999);
   h_new__1->SetEntries(85245);
   h_new__1->SetStats(0);
   h_new__1->GetXaxis()->SetTitle("M_{GT-3}^{2#nu}");
   h_new__1->GetXaxis()->CenterTitle(true);
   h_new__1->GetXaxis()->SetLabelFont(43);
   h_new__1->GetXaxis()->SetLabelSize(15);
   h_new__1->GetXaxis()->SetTitleSize(20);
   h_new__1->GetXaxis()->SetTitleOffset(1);
   h_new__1->GetXaxis()->SetTitleFont(43);
   h_new__1->GetYaxis()->SetTitle("g_{A}");
   h_new__1->GetYaxis()->CenterTitle(true);
   h_new__1->GetYaxis()->SetLabelFont(43);
   h_new__1->GetYaxis()->SetLabelSize(15);
   h_new__1->GetYaxis()->SetTitleSize(20);
   h_new__1->GetYaxis()->SetTitleOffset(1);
   h_new__1->GetYaxis()->SetTitleFont(43);
   h_new__1->GetZaxis()->SetTitleOffset(1);
   h_new__1->Draw("");

Now the accociated code… You might have to adjust this to get it to work.

You probably want to append this to the end of the “data” macro (above)

    TCanvas *c_new = new TCanvas("c_new", "c_new");
    c_new->SetTicks(2, 2);
    c_new->SetRightMargin(0.15);
    c_new->SetBottomMargin(0.15);
    if(0) // change to 1 to demonstrate the COLZ part
    {
        h_new->Draw("colz");
        c_new->Update();

        TPaletteAxis *palette2 = (TPaletteAxis*)h_new->GetListOfFunctions()->FindObject("palette");
        palette2->SetX1NDC(0.88 + 0.03);
        palette2->SetX2NDC(0.92 + 0.03);
        palette2->SetY1NDC(0.15);
        palette2->SetY2NDC(0.9);
        palette2->Draw();
        gPad->Modified();
        gPad->Update();
        c_new->Modified();
    }

    /* you probably don't need this
    TH2D *h_new_clone = (TH2D*)h_new->Clone();
    for(Int_t j = 1; j <= h_new_clone->GetNbinsY(); ++ j)
    {
        for(Int_t i = 1; i <= h_new_clone->GetNbinsX(); ++ i)
        {
            double content = h_new_clone->GetBinContent(i, j);
            if(content == 0.0)
            {
                h_new_clone->SetBinContent(i, j, std::numeric_limits<double>::infinity());
            }
        }
    }
    */

    // how I saved the data, you need to remove this and replace with some way of loading
    // the data from the .C macro
    h_new_clone->SaveAs("h_new_clone.C");
    std::cin.get();

    const double usermax = 10.0;
    std::cout << "SetRangeUser(" << cmin << ", " << usermax << ")" << std::endl;
    h_new_clone->GetZaxis()->SetRangeUser(cmin, usermax);
    double clevels[2] = {cmin + 2.30, cmin + 4.61}; // cmin approximatly = 0.0, 0 will be good enough
    h_new_clone->SetContour(2, clevels);
    h_new_clone->SetLineColor(kBlack);
    h_new_clone->SetLineWidth(2.0);
    if(0) // change to draw with "cont"
    {
        h_new_clone->Draw("cont3same");
    }
    else
    {
        h_new_clone->Draw("cont");
    }

However I’m not convinced this is a bug, unless you believe it is?

I suspect the correct regions are being drawn, however these are not the regions I wanted to draw.

It may be the case that someone with more knowledge knows another technique to shading this plot correctly.

I guess, problem is in algorithm of doing contour plot.
It fails to build closed contour, but anyway draws filled area - this should not happen.
But it will be a real challenge to fix the problem.

The only thing I can suggest - do not use plain “cont” draw option for such histograms.
You can choose many others options without filled area - cont1, cont2, cont3.

cont1, cont2 and cont3 are all variations on drawing lines I believe?

I agree with you this is probably not something that should be fixed in ROOT code but my macro.

Is there a way to do something like -

  • get a list of contour vertices
  • add new vertices manually
  • draw this as a filled are

If something like this is possible then I can fix the issue in my macro.

I can show you an example of what we are trying to achieve. This is for a different experiment with different data (arXiv 1901.03871v2 if you want to find the original paper) however the principle is the same.

image

There are two different color shaded regions, light yellow, and yellow… Perhaps this figure lends itself to be easier to draw since the Z values get larger from the bottom left to the top right… Whereas for our data there is a minimum region band across the phase space.

Hi,

First of all, it is not good idea to use infinite value as bin content - produced ROOT script is invalid.
Just use any large number instead.

It is really not trivial trying to fix this problem.
Some time ago I convert contour-plot building function to JavaScript and provide it in JSROOT.
With some workaround one could get following picture:


Here is JSROOT link. If you agree, I will use it for internal tests.

Problem, that algorithm works by chance and may fail by other kind of histograms.
But one can try to improve it.

In principle, one could back-port my fixes to ROOT THistPainter class (if @Axel and @couet agreed), but it could be complicated - JavaScript is much more flexible in such respect.

Regards,
Sergey

I can’t comment on the javascript suggestion since I am not a JS user.

I wonder if perhaps there is a different approach to this problem.

The figure I am trying to produce now could possibly be produced using contours from a previous figure… Which looks like this…

Is it possible to get the x,y points of the contours on this figure as an array of values?

Ok there are several sets of contours here. They are produced from 2 different histograms. I only require the lighter grey ones.

Is such a thing possible?

void colcontsame() {
   TH2F *h1 = new TH2F("h1","h1",100,-10,10,100,-10,10);
   TH2F *h2 = new TH2F("h2","h2",40,-3,3,40,-3,3);
   for (Int_t i=0;i<10000;i++) {
      double x,y;
      gRandom->Rannor(x,y);
      h1->Fill(5*x,5*y,4);
      if(x<0 && y<0) h2->Fill(x,y,3);
   }
   h1->SetFillColor(1);
   h2->SetLineColor(kRed);
   h2->SetContour(5);
   h1->Draw("col");
   h2->Draw("cont3 same");
   gPad->SetLogz();
}

I have been doing some searching, and I found this

It seems that it might be possible to get the x,y coordinates of contours, but that this does not work for “CONT3SAME”, only “CONT” drawing options.

I will ask another question about it as this has become a different issue and this appears to be a bug.

@linev can you share with @Birdsall how to plot this even if he’s not a JS user? :slight_smile:

In principle, any ROOT TCanvas can be shown with JSROOT just by starting root --web like:

root --web hsimple.C

One will get canvas displayed in web browser, can interact with it and store images via menu commands.

In this particular case JavaScript code is not yet in ROOT repository. But one can clone git repository and set shell variable pointing to that location:

export JSROOTSYS=/home/user/git/jsroot/
1 Like

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