PDA

View Full Version : Scatter graph



elcuco
21st December 2007, 15:35
Hi,

For a simple application in data-mining I decided to use QWT as a way to visually display the clusters found by some algorithms. Basically I need a scatter graph, but I did not understand how to make such.

The documentation is great when it deals with the classes, but it lacks guide for "tasks". I am looking for "how to do stuff" and not "how stuff work". It would be great if the screen shot images would display some basic code to make that screen shot.

Uwe
21st December 2007, 17:14
Insert a QwtPlotCurve with a NoCurve style and any QwtSymbol you like. Something like:


MyPlot::MyPlot(QWidget *parent)
QwtPlot(parent)
{
_curve = new QwtPlotCurve();
_curve->setCurveStyle(QwtPlotCurve::NoCurve);

QwtSymbol symbol;
symbol.setStyle(QwtSymbol::XCross);
symbol.setSize(QSize(6, 6));
_curve->setSymbol(symbol);

...
}

Of course you also have to assign your samples. You can copy them into one of the classes you can pass to QwtPlotCurve::setData, but you can also implement your own type of QwtData, that works as a bridge between your data and the curve ( similar to implementing a model ) without having to copy something.

HTH,
Uwe

elcuco
26th December 2007, 21:50
Thanks, that's working (using QwtPolygonFData on my case).

Now, I need to assign to each node a color, and some need to be drawn using a different symbol. Is this possible?

Uwe
27th December 2007, 09:10
Now, I need to assign to each node a color, ... Does every point need a different color and what does the color represent ?



and some need to be drawn using a different symbol.How many are these points and do they need the same different symbol ?

Uwe

elcuco
27th December 2007, 10:33
I need to divide the nodes on the graphs to n clusters, each cluster will be painted in different color. Each cluster will have a center. The number of clusters is small, 2 < n < 8. I would like to mark the centroid of each cluster differently then other nodes.

Visit the following link to have an idea of what I need to implement:
http://en.wikipedia.org/wiki/K-means_algorithm

Uwe
27th December 2007, 12:48
QwtPlotCurve is designed to display a unique type of symbol for all points. If you want to change this you need to reimplement drawSymbols:


virtual void YourPlotCurve::drawSymbols(QPainter *painter,
const QwtSymbol &symbol,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
int from, int to) const
{
for (int i = from; i <= to; i++)
{
const int xi = xMap.transform(x(i));
const int yi = yMap.transform(y(i));

rect.moveCenter(QPoint(xi, yi));

QwtSymbol yourSymbol = symbol:
// now assign your individual properties
// ...
yourSymbol.draw(painter, rect);
}
}

If you need the PaintFiltered mode the code is more complicated, see qwt_plot_curve.cpp.

Note, that Qwt is open source and you can always look at the implementation of QwtPlotCurve to see what hooks are available and how they play together.

Uwe