QCustomPlot Discussion and Comments

QCPGraph/Curve with varying color ?Return to overview

Hi,
I'd need to draw a line (QCPGraph or QCPCurve) with the color of each "point" of the line depending on a value associated to this point.

Said otherwise, for each (x,y) point on my curve I have a value (z) that define the color of that point, and some sort of "color interpolation" between points (like a QCPColorGradient).

Said otherwise, I have points (x,y,z) in 3d space and I want to plot them in the XY plane with the z info encoded in the color.

Any way to do this ?

Thanks !

QPen has the method setBrush(QBrush); http://doc.qt.io/qt-5/qpen.html#setBrush
QBrush has a constructor that takes a gradient as a parameter http://doc.qt.io/qt-5/qbrush.html#QBrush-9

QLinearGradient lGrad(QPointF(0,0), QPointF(0,500));
lGrad.setColorAt(0, QColor(Qt::red));
lGrad.setColorAt(1, QColor(Qt::green));
QBrush lBrush(lGrad);
myPen.setBrush(lBrush);

myGraph->setPen(myPen);

You still need to calculate the "start", "final" points, and intermediate points for the linear gradient. (In the coordinate system of the device - QWidget)

Carefully re-read your post and realized that I advised not quite what you need)

If the grid formed by a set of points (x, y) is regular, then perhaps QCPColorMap will suit you

Thanks define true false, but that won't help, as you noticed.

Even in Matlab this doesn't seem to be trivial, see https://stackoverflow.com/questions/31685078/change-color-of-2d-plot-line-depending-on-3rd-value

Nobody ?

I'd like to do somethink like this : https://i.imgur.com/MLAEuad.png