Results 1 to 4 of 4

Thread: Strange lines in beginner plot...

  1. #1
    Join Date
    Dec 2011
    Location
    Jena, Germany
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Strange lines in beginner plot...

    Hi,

    first post, so please don't be too strict with me.

    I'm biologist, not programmer, and it took me a while to get to this point. Now I'm stuck with a problem which I think is easy for a qwt-advanced. One of my final goals is to visualize data from an ad-converter with qwt. For getting accustomed with matters I tried to produce a simple plot with code I found somewhere (in a header?), but when I compile it, I find strange lines besides the curves I would expect:

    Qt Code:
    1. class vtPlot : public QwtPlot
    2. {
    3. Q_OBJECT
    4. static int const NPOINTS = 150;
    5. double x[NPOINTS], ysin[NPOINTS], ycos[NPOINTS];
    6.  
    7. public:
    8. explicit vtPlot(QObject *parent = 0);
    9. void *myData();
    10. QwtPointArrayData *myArray[2];
    11. };
    12.  
    13. vtPlot::vtPlot(QObject *parent)
    14. {
    15. }
    16.  
    17. void *vtPlot::myData()
    18. {
    19. for(int i = 0; i < NPOINTS; i++)
    20. {
    21. x[i] = 0.1*i;
    22. ysin[i] = sin(x[i]);
    23. ycos[i] = cos(x[i]);
    24. }
    25. myArray[0] = new QwtPointArrayData(x,ysin,(sizeof(x)+sizeof(ysin))); // actually not sure if the third argument is correct
    26. myArray[1] = new QwtPointArrayData(x,ycos,(sizeof(x)+sizeof(ycos)));
    27. }
    28.  
    29.  
    30. int main(int argc, char *argv[])
    31. {
    32. QApplication a(argc, argv);
    33. MainWindow w;
    34.  
    35. vtPlot *myPlot = new vtPlot(&w);
    36. QwtPlotCurve *curve1 = new QwtPlotCurve("sinus");
    37. QwtPlotCurve *curve2 = new QwtPlotCurve("cosinus");
    38.  
    39. myPlot->myData();
    40.  
    41. curve1->setData(myPlot->myArray[0]);
    42. curve1->attach(myPlot);
    43.  
    44. curve2->setData(myPlot->myArray[1]);
    45. curve2->attach(myPlot);
    46.  
    47. myPlot->setTitle("Voltage [mV] - Time [s]");
    48. myPlot->setAxisTitle(myPlot->yLeft,"Voltage [mV]");
    49. myPlot->setAxisTitle(myPlot->xBottom,"Time [s]");
    50.  
    51. w.setCentralWidget(myPlot);
    52.  
    53. w.show();
    54.  
    55. return a.exec();
    56. }
    To copy to clipboard, switch view to plain text mode 

    Gives me this:
    graph.jpg

    Of course I ensure having searched the forum and the www for help, but I wasn't successful.
    Any hint would be appreciated.

    Thanks a lot,
    Emi
    Last edited by emigrand; 6th December 2011 at 23:02.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Strange lines in beginner plot...

    Here you go, you already knew the problem but were not able to fix it. Here the fully working code and sample output
    Qt Code:
    1. #include <QtGui> // <<<<<<<<<<<<<<< edited
    2. #include <qwt_plot.h> // <<<<<<<<<<<<<<< edited
    3. #include <qwt_plot_curve.h> // <<<<<<<<<<<<<<< edited
    4. #include <qwt_series_data.h> // <<<<<<<<<<<<<<< edited
    5.  
    6.  
    7. class vtPlot : public QwtPlot
    8. {
    9. Q_OBJECT
    10. static int const NPOINTS = 150;
    11. double x[NPOINTS], ysin[NPOINTS], ycos[NPOINTS];
    12.  
    13.  
    14. public:
    15. explicit vtPlot(QObject *parent = 0);
    16. void myData(); // <<<<<<<<<<<<<<< edited
    17. QwtPointArrayData *myArray[2];
    18. };
    19.  
    20.  
    21. vtPlot::vtPlot(QObject *parent)
    22. {
    23. }
    24.  
    25.  
    26. void vtPlot::myData() // <<<<<<<<<<<<<<< edited
    27. {
    28. for(int i = 0; i < NPOINTS; i++)
    29. {
    30. x[i] = 0.1*i;
    31. ysin[i] = sin(x[i]);
    32. ycos[i] = cos(x[i]);
    33. }
    34. myArray[0] = new QwtPointArrayData(x,ysin,NPOINTS); // <<<<<<<<<<<<<<< edited
    35. myArray[1] = new QwtPointArrayData(x,ycos,NPOINTS); // <<<<<<<<<<<<<<< edited
    36. }
    37.  
    38.  
    39.  
    40.  
    41. int main(int argc, char *argv[])
    42. {
    43. QApplication a(argc, argv);
    44. QMainWindow w; // <<<<<<<<<<<<<<< edited
    45.  
    46.  
    47. vtPlot *myPlot = new vtPlot(&w);
    48. QwtPlotCurve *curve1 = new QwtPlotCurve("sinus");
    49. QwtPlotCurve *curve2 = new QwtPlotCurve("cosinus");
    50.  
    51.  
    52. myPlot->myData();
    53.  
    54.  
    55. curve1->setData(myPlot->myArray[0]);
    56. curve1->attach(myPlot);
    57.  
    58.  
    59. curve2->setData(myPlot->myArray[1]);
    60. curve2->attach(myPlot);
    61.  
    62.  
    63. myPlot->setTitle("Voltage [mV] - Time [s]");
    64. myPlot->setAxisTitle(myPlot->yLeft,"Voltage [mV]");
    65. myPlot->setAxisTitle(myPlot->xBottom,"Time [s]");
    66.  
    67.  
    68. w.setCentralWidget(myPlot);
    69.  
    70.  
    71. w.show();
    72.  
    73.  
    74. return a.exec();
    75. }
    76.  
    77.  
    78. #include "main.moc" // <<<<<<<<<<<<<<< edited
    To copy to clipboard, switch view to plain text mode 
    Sample.jpg
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Dec 2011
    Location
    Jena, Germany
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Strange lines in beginner plot...

    Thanks a lot, Santosh! Works perfectly. Now I am motivated again.
    For the next problem I promise to post the complete code, including headers.

    Have a nice day!
    Emi

  4. #4
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Strange lines in beginner plot...

    Hi emi,

    there is a section for qwt in this forum, you should post there next time... not all qwt-specialists read here.

    Felix

Similar Threads

  1. Replies: 4
    Last Post: 11th May 2011, 19:15
  2. Replies: 3
    Last Post: 18th June 2010, 13:18
  3. plot with hor. lines and text
    By hugo vanwoerkom in forum Qwt
    Replies: 2
    Last Post: 10th March 2010, 17:00
  4. Help! about Qt for beginner!!
    By Cantora in forum Newbie
    Replies: 9
    Last Post: 2nd April 2009, 00:11
  5. Replies: 7
    Last Post: 22nd September 2008, 22:05

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
  •  
Qt is a trademark of The Qt Company.