QCustomPlot Discussion and Comments

result displayed in a heatmap slightly shiftedReturn to overview

Hi there,
Im trying to plot a heatmap from a root CERN TH2D histogram. I think my data is correct since it matches what I'm expecting. But when I try to display the result, my data points are not plotted where I'm expecting them; they are shifted.
To make it a little bit more clear, if I'm watching (x, y) = (104, 75), the result seems to be displayed at (104.5, 75.5)...

I ran the code in debug mode and the couple (x, y) from my data set is always (104, 75) as deep as I can go. So I feel the data is correctly transmitted.
Though, when I plot it, the lower left corner of this point appears at (104.5, 75.5)...
Here is a plot of the result : https://imgur.com/a/Higs8Ib
What I was expecting, is this little white square to be centered on (x, y) = (104, 75).
Thank you very much for your help.
Regards
Olivier


int plot_widget::plot_hit_map(
  const std::vector<daq::mapping::coordinate_dxy>& coordinates, //
  const QString&                                   title,       //
  const QString&                                   xlabel,      //
  const QString&                                   ylabel)
{
  zeros.clear();
  plot->setInteractions(QCP::iSelectItems | QCP::iRangeDrag | QCP::iRangeZoom);
  plot->xAxis->setLabel(xlabel);
  plot->yAxis->setLabel(ylabel);

  auto map = create_new_map();
  map->colorScale()->setDataRange(QCPRange(0, 1));

  //  TH2::TH2(const char* name, const char* title, Int_t nbinsx, Double_t
  // xlow, Double_t xup, Int_t nbinsy, Double_t ylow, Double_t yup);
  auto heatmap =
    std::make_unique<TH2C>("hm", title.toLatin1(), 128, 0, 127, 128, 0, 127);

  map->data()->setRange(QCPRange(0, 127), QCPRange(0, 127));

  for (auto& c : coordinates)
    if (!(c.x == 0 && c.y == 0)) heatmap->Fill(c.x, c.y);
    else
      zeros.push_back(c);

  int xc, yc;
  for (int x{1}; x < 128; x++)
  {
    for (int y{1}; y < 128; y++)
    {
      Int_t data = heatmap->GetBinContent(x, y);
      map->data()->coordToCell(x, y, &xc, &yc);
      map->data()->setCell(xc, yc, data);
    }
  }

  plot->axisRect()->setupFullAxesBox();
  plot->xAxis->setLabel(xlabel);
  plot->yAxis->setLabel(ylabel);
  plot->rescaleAxes();
  plot->legend->setVisible(false);
  plot->replot();

  return 0;
}

Sorry guys,
the problem is coming from my TH2C histogram...
dunno if I can delete this post.
osfe