Results 1 to 6 of 6

Thread: Scatter graph

  1. #1
    Join Date
    Jan 2006
    Posts
    368
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Scatter graph

    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.

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Scatter graph

    Insert a QwtPlotCurve with a NoCurve style and any QwtSymbol you like. Something like:

    Qt Code:
    1. MyPlot::MyPlot(QWidget *parent)
    2. QwtPlot(parent)
    3. {
    4. _curve = new QwtPlotCurve();
    5. _curve->setCurveStyle(QwtPlotCurve::NoCurve);
    6.  
    7. QwtSymbol symbol;
    8. symbol.setStyle(QwtSymbol::XCross);
    9. symbol.setSize(QSize(6, 6));
    10. _curve->setSymbol(symbol);
    11.  
    12. ...
    13. }
    To copy to clipboard, switch view to plain text mode 

    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

  3. #3
    Join Date
    Jan 2006
    Posts
    368
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Scatter graph

    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?

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Scatter graph

    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

  5. #5
    Join Date
    Jan 2006
    Posts
    368
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Scatter graph

    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

  6. #6
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Scatter graph

    QwtPlotCurve is designed to display a unique type of symbol for all points. If you want to change this you need to reimplement drawSymbols:

    Qt Code:
    1. virtual void YourPlotCurve::drawSymbols(QPainter *painter,
    2. const QwtSymbol &symbol,
    3. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    4. int from, int to) const
    5. {
    6. for (int i = from; i <= to; i++)
    7. {
    8. const int xi = xMap.transform(x(i));
    9. const int yi = yMap.transform(y(i));
    10.  
    11. rect.moveCenter(QPoint(xi, yi));
    12.  
    13. QwtSymbol yourSymbol = symbol:
    14. // now assign your individual properties
    15. // ...
    16. yourSymbol.draw(painter, rect);
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 

    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

Similar Threads

  1. Graph plotting
    By steg90 in forum Qt Programming
    Replies: 13
    Last Post: 6th April 2011, 11:30
  2. Signal and slot connection graph
    By fahlen in forum General Discussion
    Replies: 4
    Last Post: 27th November 2007, 14:47
  3. Line Graph
    By sabeesh in forum Qt Programming
    Replies: 2
    Last Post: 24th July 2007, 10:13
  4. Threading and plotting graph in same program.
    By sar_van81 in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 9th May 2007, 21:42
  5. How to plot a graph in Qt ?
    By vinod in forum Qt Programming
    Replies: 2
    Last Post: 27th April 2006, 14:44

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.