View Full Version : How to make curves with empty intervals in them?
alex_sh
17th September 2010, 11:46
Hello,
I could not find anything related in Qwt docs so I'm posting here. I'm using Qwt6 SVN and I need to draw a curve (actually, a straight horizontal line), but it must not be continuous. I'm attaching a screenshot to show what I mean. The green line runs under the red one, and the red one consists of multiple pieces.
I thought about creating multiple curves for the red one, but I need exactly one legend item for it. Preferably, the settings (color, thickness, etc...) applied to the curve should affect all its pieces.
Any idea how I may accomplish that?
Thanks a lot in advance!
5200
Astronomy
17th September 2010, 13:29
Hi,
you mean
// Insert markers
// ...a horizontal line at y = 0...
QwtPlotMarker *mY = new QwtPlotMarker();
mY->setLabel(QString::fromLatin1("y = 0"));
mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
mY->setLineStyle(QwtPlotMarker::HLine);
mY->setYValue(0.0);
mY->attach(this);
wouldn't work for you?
Maybe you cann ad a simple constant function:
y = f(x) like y=1 | x[1,2]
e.g.:
// Insert new curves
QwtPlotCurve *pConstantFunction = new QwtPlotCurve("y = f(1)");
#if QT_VERSION >= 0x040000
pConstantFunction->setRenderHint(QwtPlotItem::RenderAntialiased);
#endif
pConstantFunction->setPen(QPen(Qt::red));
pConstantFunction->setData(....) //your const f() or an array of f(..)?
pConstantFunction->attach(this);
or an array of functions?
y = f(x); y=1 | x[1,2]
y = f(x); y=1 | x[3,4]
y = f(x); y=1 | x[7,10]
that will simulate your seperated line?
greetz AP.
alex_sh
17th September 2010, 13:44
Astronomy, thanks for your answer.
Hi,
you mean
// Insert markers
// ...a horizontal line at y = 0...
QwtPlotMarker *mY = new QwtPlotMarker();
mY->setLabel(QString::fromLatin1("y = 0"));
mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
mY->setLineStyle(QwtPlotMarker::HLine);
mY->setYValue(0.0);
mY->attach(this);
wouldn't work for you?
If I understand it correctly, this would not create a legend item which I need (or create multiple items? I'm not sure). A possible workaround would be to add another "dummy" curve with nothing (or a single point) to display, just to get the legend item. I would also need to mirror the curve style changes to the marker (I have a dialog that controls curve appearance). I was hoping for something a bit more straightforward.
Maybe you cann ad a simple constant function:
y = f(x) like y=1 | x[1,2]
e.g.:
// Insert new curves
QwtPlotCurve *pConstantFunction = new QwtPlotCurve("y = f(1)");
#if QT_VERSION >= 0x040000
pConstantFunction->setRenderHint(QwtPlotItem::RenderAntialiased);
#endif
pConstantFunction->setPen(QPen(Qt::red));
pConstantFunction->setData(....) //your const f() or an array of f(..)?
pConstantFunction->attach(this);
or an array of functions?
y = f(x) y=f(1) | x[1,2]
y = f(x) y=f(1) | x[3,4]
y = f(x) y=f(1) | x[7,10]
that will simulate your seperated line?
You mean just add one curve for each line? That would create multiple legend items (I need only one), and I would have to synchronize the curve appearance settings between them. I'll probably go with this one (once I find out how to hide the curve legend items), unless there is some simpler solution out there.
Thanks
Astronomy
17th September 2010, 13:51
Yes the first is just a horizontal line.
The Array of constant functions will produce this:
"_________ _________ ______________"
f1(1). .......f2(1) .........f3(1)
three or more f(..) at the same y-position, but with different x-points will possibly work..
greetz AP.
Uwe
20th September 2010, 06:34
1) If you want to display a curve with gaps overload QwtPlotCurve::drawXY ( don't use markers ).
2) By curve->setItemAttribute(QwtPlotItem::Legend, ...) you can control if a curve ( or any other QwtPlotItem ) should have an entry on the legend.
Uwe
alex_sh
20th September 2010, 18:01
Thank you both.
I solved this by creating multiple curves and disabling the legend items (using setItemAttribute()) on all of them except the first one.
Note that I had to disable the legend item _before_ the attach() call, or it would still allocate the space in the legend, but draw nothing there.
P.S. There's no QwtPlotCurve::drawXY() in Qwt6, or am I mistaken?
Galak
26th October 2010, 09:02
Hi,
I have resolved this problem to using nan values, see the attached files
5400
5401
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.