QCustomPlot Discussion and Comments

How to make point's text lable adjust with scale of x-axis and y-axisReturn to overview

x[0] = 10;
y[0] = 50;

x_offset = 0.7;
y_offset = 1.0;
QCPItemText *textLabel = new QCPItemText(ui->widget);
textLabel->position->setCoords(x[0]- x_offset, y[0] + y_offset); // place position at center/top of axis rect
textLabel->setColor(Qt::white);
QString str;
str.sprintf("%d", 10);

textLabel->setText(str);
textLabel->setFont(QFont(font().family(), 8)); // make font a bit larger


The problem is , if x-axis range is (-20,20), y-axis range is (-50,100), the text lable is near the point(x[0],y[0]) properly. when x-axis range is set to (-200,200), y-axis range is set to (-500,500), the lable is merge with point(x[0],y[0]) because of large scale, what I want is lable's postion is near the point from the eye of view

how to solve this problem? for this kind of problem,MATLAB solved it perfectly, point and its lable are
displayed rightly under different scale x-axis and y-axis

This is because you are applying a fixed offset of your label in coordinate space (0.7 and 1.0).

Instead, you should change the position alignment on the QCPItemText (e.g. to left align horizontally and center vertically), and increase its padding.

The documentation and item tutorial will give you a better idea about the different positioning possibilities with QCP items.