PDA

View Full Version : how to plot scatter graph?



rambo83
25th February 2010, 12:24
Hello,

I would like to plot some kind of scatter graph on my QwtPlot to indicate feasible and infeasible regions on a spectrogramm, which is displayed on this QwtPlot, too. I have got some constraints or inequalities of type:
f(x1, x2) >= 0 , e.g. x2- x1^2 >=0 . Now, I have to calculate which coordinates of the plot violate the constraint and thus indicate it with a cross, for example. In forum, I have seen already that a scatter plot can be done by means of QwtPlotCurve, whereas one must set NOCURVE attribute to it:


_curve = new QwtPlotCurve();

_curve->setCurveStyle(QwtPlotCurve::NoCurve);


QwtSymbol symbol;

symbol.setStyle(QwtSymbol::XCross);

symbol.setSize(QSize(6, 6));

_curve->setSymbol(symbol);

But how should I set the data to this curve then? If I use the example "SimplePlot" where a curve gets its data from SimpleData class, then it iterates only through x, but I need to iterate both through x1 and x2.
My idea was to write IF and ELSE conditions within constraint function, which returns 0 or 1 in regards to satisfying the constraint, thus I would get then a data array with 0 and 1 and could display it as scatter graph above the spectrogram plot.

Please give me a hint, which data container to use or generally how to manage my plan.

Thank you


class SimpleData: public QwtData
{
// The x values depend on its index and the y values
// can be calculated from the corresponding x value.
// So we don´t need to store the values.
// Such an implementation is slower because every point
// has to be recalculated for every replot, but it demonstrates how
// QwtData can be used.

public:
SimpleData(double(*y)(double), size_t size):
d_size(size),
d_y(y)
{
}

virtual QwtData *copy() const
{
return new SimpleData(d_y, d_size);
}

virtual size_t size() const
{
return d_size;
}

virtual double x(size_t i) const
{
return 0.1 * i;
}

virtual double y(size_t i) const
{
return d_y(x(i));
}
private:
size_t d_size;
double(*d_y)(double);
};