QCustomPlot Discussion and Comments

scatterplot with different point sizeReturn to overview

hi
i am trying to create a scatter plot but with a predefined variable diameter size for each point.
can any body please help me how to do it?

Hmm, interesting question
I think

void drawShape(QCPPainter *painter, double x, double y) const;

should be virtual to solve this problem

it is not clear to me, i want to pass an array to it.
Could you please implement it and let me know how to use it.
I could not debug the code, it is very complicated.

this will only work if there is only one value for each key

//inheritance
class MyGraph : public QCPGraph{
...
  QMap<double, double> keyToPointSize; // key is X coord
  void initScattersSize(double *key, double *size){
    const int numPoint = 100;
    for(int i = 0; i<numPoint; i++)
      keyToPointSize.insert(key[i], size[i]);
  }

  //override parent virtual function
  void drawScatterPlot(QCPPainter *painter, const QVector<QPointF> &scatters, const QCPScatterStyle &style) const
  {
    applyScattersAntialiasingHint(painter);
    style.applyTo(painter, mPen);
    
    double size;
    for (int i=0; i<scatters.size(); ++i)
      size = keyToPointSize.value(
         keyAxis()->pixelToCoord( scatters.at(i).x() ) //if axis at bottom or top
      );
      painter->drawEllipse(QPointF(scatters.at(i).x() , scatters.at(i).y()), size, size);
  }
}