Creating surface plot from 2D vector

Hi there,

I’ve read a few bits online about creating surface plots, but none of them quite seem to fit what I need; I have a 2D vector of ints in the format 100x2048 and would like to plot this in 3D to see the shape of the data, but I’m not sure of how to phrase the code.

Any hints would be appreciated!

Thanks,
Alistair


ROOT Version: 6.12
Platform: Linux
Compiler: Not Provided


I would recommend a TGraph2D if the point are not on a regular grid. But a TH2I is also an good (simpler) way if the point are on a regular grid.

1 Like

Thanks; I thought about TGraph2D, but the plots seem to require three vectors - Would it be a case of TGraph2D *surfaceplot = new TGraph2D(bigvect); or would I need to specify columns and rows somehow?

So it seems your array matches better a TH2.

Can you post your 2D vector here ?

Sorry for the delayed reply; I tried to post the entire thing which did not work (it turns out that copying and pasting ~1,000,000 characters takes a lot of memroy!)

Here is an extract, and it continues like this with regular vectors containing 100 points until the end of the file.

(std::vector<std::vector<int> > &) { { 616, 618, 619, 609, 618, 600, 604, 594, 618, 623, 608, 623, 622, 608, 613, 614, 623, 619, 598, 608, 616, 606, 616, 617, 616, 606, 620, 617, 612, 606, 620, 612, 614, 604, 610, 615, 623, 616, 630, 617, 629, 618, 604, 605, 623, 626, 626, 603, 609, 619, 633, 629, 605, 612, 608, 613, 608, 623, 612, 630, 616, 622, 620, 613, 588, 633, 613, 625, 613, 616, 619, 634, 619, 628, 615, 611, 617, 612, 611, 614, 613, 636, 596, 613, 621, 608, 612, 609, 606, 620, 612, 623, 620, 607, 607, 610, 611, 610, 601 }, { 616, 618, 619, 609, 618, 600, 604, 594, 618, 623, 608, 623, 622, 608, 613, 614, 623, 619, 598, 608, 616, 606, 616, 617, 616, 606, 620, 617, 612, 606, 620, 612, 614, 604, 610, 615, 623, 616, 630, 617, 629, 618, 604, 605, 623, 626, 626, 603, 609, 619, 633, 629, 605, 612, 608, 613, 608, 623, 612, 630, 616, 622, 620, 613, 588, 633, 613, 625, 613, 616, 619, 634, 619, 628, 615, 611, 617, 612, 611, 614, 613, 636, 596, 613, 621, 608, 612, 609, 606, 620, 612, 623, 620, 607, 607, 610, 611, 610, 601 }, { 595, 607, 604, 607, 594, 617, 596, 607, 612, 602, 588, 611, 603, 609, 618, 606, 607, 590, 607, 587, 619, 607, 607, 610, 614, 601, 611, 610, 603, 601, 593, 613, 618, 615, 616, 618, 591, 611, 618, 612, 613, 608, 598, 606, 616, 613, 622, 609, 607, 617, 611, 610, 601, 611, 607, 622, 618, 609, 613, 609, 597, 600, 624, 614, 605, 616, 610, 601, 611, 618, 604, 594, 599, 629, 618, 614, 612, 604, 617, 604, 616, 604, 596, 613, 615, 601, 604, 614, 613, 614, 615, 614, 610, 609, 618, 611, 624, 607, 606 }, { 595, 607, 604, 607, 594, 617, 596, 607, 612, 602, 588, 611, 603, 609, 618, 606, 607, 590, 607, 587, 619, 607, 607, 610, 614, 601, 611, 610, 603, 601, 593, 613, 618, 615, 616, 618, 591, 611, 618, 612, 613, 608, 598, 606, 616, 613, 622, 609, 607, 617, 611, 610, 601, 611, 607, 622, 618, 609, 613, 609, 597, 600, 624, 614, 605, 616, 610, 601, 611, 618, 604, 594, 599, 629, 618, 614, 612, 604, 617, 604, 616, 604, 596, 613, 615, 601, 604, 614, 613, 614, 615, 614, 610, 609, 618, 611, 624, 607, 606 }, { 599, 602, 591, 596, 601, 589, 613, 611, 604, 603, 591, 588, 587, 594, 613, 599, 601, 593, 594, 592, 607, 585, 600, 595, 597, 583, 599, 594, 606, 604, 592, 592, 596, 600, 602, 598, 591, 597, 607, 606, 614, 600, 611, 602, 589, 590, 592, 592, 600, 583, 611, 598, 595, 615, 590, 586, 613, 610, 614, 596, 606, 585, 594, 619, 579, 596, 604, 603, 604, 592, 600, 607, 600, 604, 617, 589, 589, 628, 604, 594, 584, 590, 589, 598, 606, 581, 587, 623, 594, 614, 596, 596, 603, 604, 586, 596, 606, 589, 591 }, { 599, 602, 591, 596, 601, 589, 613, 611, 604, 603, 591, 588, 587, 594, 613, 599, 601, 593, 594, 592, 607, 585, 600, 595, 597, 583, 599, 594, 606, 604, 592, 592, 596, 600, 602, 598, 591, 597, 607, 606, 614, 600, 611, 602, 589, 590, 592, 592, 600, 583, 611, 598, 595, 615, 590, 586, 613, 610, 614, 596, 606, 585, 594, 619, 579, 596, 604, 603, 604, 592, 600, 607, 600, 604, 617, 589, 589, 628, 604, 594, 584, 590, 589, 598, 606, 581, 587, 623, 594, 614, 596, 596, 603, 604, 586, 596, 606, 589, 591 }, { 612, 610, 603, 627, 612, 620, 602, 609, 621, 616, 598, 618, 610, 596, 624, 602, 603, 614, 619, 586, 602, 616, 621, 608, 630, 631, 622, 627, 630, 609, 598, 618, 620, 613, 603, 603, 617, 621, 620, 594, 607, 618, 614, 620, 600, 616, 631, 619, 622, 623, 610, 608, 614, 609, 607, 603, 617, 626, 615, 607, 632, 624, 610, 613, 611, 612, 602, 607, 610, 618, 605, 613, 600, 638, 619, 625, 600, 604, 626, 614, 625, 614, 600, 605, 632, 623, 616, 620, 611, 606, 613, 627, 614, 623, 609, 616, 597, 635, 605 }, { 612, 610, 603, 627, 612, 620, 602, 609, 621, 616, 598, 618, 610, 596, 624, 602, 603, 614, 619, 586, 602, 616, 621, 608, 630, 631, 622, 627, 630, 609, 598, 618, 620, 613, 603, 603, 617, 621, 620, 594, 607, 618, 614, 620, 600, 616, 631, 619, 622, 623, 610, 608, 614, 609, 607, 603, 617, 626, 615, 607, 632, 624, 610, 613, 611, 612, 602, 607, 610, 618, 605, 613, 600, 638, 619, 625, 600, 604, 626, 614, 625, 614, 600, 605, 632, 623, 616, 620, 611, 606, 613, 627, 614, 623, 609, 616, 597, 635, 605 } }
{
   int arr[8][99] =
   {
      { 616, 618, 619, 609, 618, 600, 604, 594, 618, 623, 608, 623, 622, 608, 613, 614, 623, 619, 598, 608, 616, 606, 616, 617, 616, 606, 620, 617, 612, 606, 620, 612, 614, 604, 610, 615, 623, 616, 630, 617, 629, 618, 604, 605, 623, 626, 626, 603, 609, 619, 633, 629, 605, 612, 608, 613, 608, 623, 612, 630, 616, 622, 620, 613, 588, 633, 613, 625, 613, 616, 619, 634, 619, 628, 615, 611, 617, 612, 611, 614, 613, 636, 596, 613, 621, 608, 612, 609, 606, 620, 612, 623, 620, 607, 607, 610, 611, 610, 601 },
      { 616, 618, 619, 609, 618, 600, 604, 594, 618, 623, 608, 623, 622, 608, 613, 614, 623, 619, 598, 608, 616, 606, 616, 617, 616, 606, 620, 617, 612, 606, 620, 612, 614, 604, 610, 615, 623, 616, 630, 617, 629, 618, 604, 605, 623, 626, 626, 603, 609, 619, 633, 629, 605, 612, 608, 613, 608, 623, 612, 630, 616, 622, 620, 613, 588, 633, 613, 625, 613, 616, 619, 634, 619, 628, 615, 611, 617, 612, 611, 614, 613, 636, 596, 613, 621, 608, 612, 609, 606, 620, 612, 623, 620, 607, 607, 610, 611, 610, 601 },
      { 595, 607, 604, 607, 594, 617, 596, 607, 612, 602, 588, 611, 603, 609, 618, 606, 607, 590, 607, 587, 619, 607, 607, 610, 614, 601, 611, 610, 603, 601, 593, 613, 618, 615, 616, 618, 591, 611, 618, 612, 613, 608, 598, 606, 616, 613, 622, 609, 607, 617, 611, 610, 601, 611, 607, 622, 618, 609, 613, 609, 597, 600, 624, 614, 605, 616, 610, 601, 611, 618, 604, 594, 599, 629, 618, 614, 612, 604, 617, 604, 616, 604, 596, 613, 615, 601, 604, 614, 613, 614, 615, 614, 610, 609, 618, 611, 624, 607, 606 },
      { 595, 607, 604, 607, 594, 617, 596, 607, 612, 602, 588, 611, 603, 609, 618, 606, 607, 590, 607, 587, 619, 607, 607, 610, 614, 601, 611, 610, 603, 601, 593, 613, 618, 615, 616, 618, 591, 611, 618, 612, 613, 608, 598, 606, 616, 613, 622, 609, 607, 617, 611, 610, 601, 611, 607, 622, 618, 609, 613, 609, 597, 600, 624, 614, 605, 616, 610, 601, 611, 618, 604, 594, 599, 629, 618, 614, 612, 604, 617, 604, 616, 604, 596, 613, 615, 601, 604, 614, 613, 614, 615, 614, 610, 609, 618, 611, 624, 607, 606 },
      { 599, 602, 591, 596, 601, 589, 613, 611, 604, 603, 591, 588, 587, 594, 613, 599, 601, 593, 594, 592, 607, 585, 600, 595, 597, 583, 599, 594, 606, 604, 592, 592, 596, 600, 602, 598, 591, 597, 607, 606, 614, 600, 611, 602, 589, 590, 592, 592, 600, 583, 611, 598, 595, 615, 590, 586, 613, 610, 614, 596, 606, 585, 594, 619, 579, 596, 604, 603, 604, 592, 600, 607, 600, 604, 617, 589, 589, 628, 604, 594, 584, 590, 589, 598, 606, 581, 587, 623, 594, 614, 596, 596, 603, 604, 586, 596, 606, 589, 591 },
      { 599, 602, 591, 596, 601, 589, 613, 611, 604, 603, 591, 588, 587, 594, 613, 599, 601, 593, 594, 592, 607, 585, 600, 595, 597, 583, 599, 594, 606, 604, 592, 592, 596, 600, 602, 598, 591, 597, 607, 606, 614, 600, 611, 602, 589, 590, 592, 592, 600, 583, 611, 598, 595, 615, 590, 586, 613, 610, 614, 596, 606, 585, 594, 619, 579, 596, 604, 603, 604, 592, 600, 607, 600, 604, 617, 589, 589, 628, 604, 594, 584, 590, 589, 598, 606, 581, 587, 623, 594, 614, 596, 596, 603, 604, 586, 596, 606, 589, 591 },
      { 612, 610, 603, 627, 612, 620, 602, 609, 621, 616, 598, 618, 610, 596, 624, 602, 603, 614, 619, 586, 602, 616, 621, 608, 630, 631, 622, 627, 630, 609, 598, 618, 620, 613, 603, 603, 617, 621, 620, 594, 607, 618, 614, 620, 600, 616, 631, 619, 622, 623, 610, 608, 614, 609, 607, 603, 617, 626, 615, 607, 632, 624, 610, 613, 611, 612, 602, 607, 610, 618, 605, 613, 600, 638, 619, 625, 600, 604, 626, 614, 625, 614, 600, 605, 632, 623, 616, 620, 611, 606, 613, 627, 614, 623, 609, 616, 597, 635, 605 },
      { 612, 610, 603, 627, 612, 620, 602, 609, 621, 616, 598, 618, 610, 596, 624, 602, 603, 614, 619, 586, 602, 616, 621, 608, 630, 631, 622, 627, 630, 609, 598, 618, 620, 613, 603, 603, 617, 621, 620, 594, 607, 618, 614, 620, 600, 616, 631, 619, 622, 623, 610, 608, 614, 609, 607, 603, 617, 626, 615, 607, 632, 624, 610, 613, 611, 612, 602, 607, 610, 618, 605, 613, 600, 638, 619, 625, 600, 604, 626, 614, 625, 614, 600, 605, 632, 623, 616, 620, 611, 606, 613, 627, 614, 623, 609, 616, 597, 635, 605 }
   };
   auto h = new TH2I("h","h",99,0,99,8,0,8);
   for (int i=0; i<8; i++) {
      for (int j=0; j<99; j++) {
         h->SetBinContent(j+1,i+1,arr[i][j]);
      }
   }
   h->Draw("surf1");
}

1 Like

Amazing, thank you so much!

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