TGraph2D with bars

I encountered a following problem with root.

I want to draw a simple TGraph2D. But I would like to draw it simillar to 1D graph with option B - bars instead of points. I cannot find such an option for TGraph2d or 2D histogram - everything requires interpolation. I don’t want any interpolated surface, just 3d bar instead of point. Is it possible?

Lech Wiktor Piotrowski

here is an example:

#include <TMath.h>
#include <TGraph2D.h>
#include <TRandom.h>
#include <TStyle.h>
#include <TStopwatch.h>

void graph2derrors()
{
   gStyle->SetPadBorderMode(0);
   gStyle->SetFrameBorderMode(0);
   gStyle->SetCanvasBorderMode(0);

   TStopwatch timer;

   timer.Start();
   TCanvas *c = new TCanvas("c","Graph2DErrors example",0,0,600,600);
   Double_t P = 6.;
   Int_t np   = 200;

   Double_t *rx=0, *ry=0, *rz=0;
   Double_t *ex=0, *ey=0, *ez=0;

   rx = new Double_t[np];
   ry = new Double_t[np];
   rz = new Double_t[np];
   ex = new Double_t[np];
   ey = new Double_t[np];
   ez = new Double_t[np];

   TRandom *r = new TRandom();

   for (Int_t N=0; N<np; N++) {
      rx[N] = 2*P*(r->Rndm(N))-P;
      ry[N] = 2*P*(r->Rndm(N))-P;
      rz[N] = rx[N]*rx[N]-ry[N]*ry[N];
      ex[N] = r->Rndm(N);
      ey[N] = r->Rndm(N);
      ez[N] = r->Rndm(N);
   }
   gStyle->SetPalette(1);

   TGraph2DErrors *dte = new TGraph2DErrors(np, rx, ry, rz, ex, ey, ez);

   dte->SetFillColor(29);
   dte->SetMarkerSize(0.5);
   dte->Draw("E");
   gPad->Update();

   timer.Stop();

   Float_t RT=timer.RealTime();
   Float_t Cpu=timer.CpuTime();
   printf("RT   = %7.3f s, Cpu   = %7.3f s\n",RT,Cpu);
}

Well, I was thinking about error bars, but bars instead of points, like in TGraph drawn with “B” option - filled rectangels from 0 to point :slight_smile:

Do you know how to do that without interpolation in 3d?

Lech Wiktor Piotrowski

In the example I sent you there is no interpolation

There is no interpolation, for it does not draw what I want. How to draw bars below points (not error bars)?

ho I see … this option is not implemented

Hmm, I understand there is no high demand for this option? I guess implementing it would be a 10 minute work for a root developer… it’s only graphical change. Is there any chance you’ll implement it in near future?

Lech Wiktor Piotrowski

so you just want to draw vertical lines from the floor up to the z value ?

Yes. However, I would like them to be cuboid rather then line - it helps to see the data better in some cases. Just like rectangles in 1D graph with option “B”

Ok … That’s what I thought … you want a Lego plot with no equidistant bins. That is not trivial at all to implement. And we can not do that very quickly. So for this kind of representation you would need to use the interpolation ie: plot the graph with option LEGO

I see. For my data I get lots of interpolation errors, that’s why I was asking question here. With all these errors, it takes quite long for some amount of data to be drawn. Although, I havent’ investigeted these errors at all.

Thankyou for the answer,
Lech Wiktor Piotrowski

if you send me the errors you get I may help you.