Results 1 to 4 of 4

Thread: 2D array data plot!

  1. #1
    Join Date
    Mar 2009
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question 2D array data plot!

    Hi QWT Forumers!

    I'd like to draw 2d array data and it is my first experience with QWT, everything is OK, but the following code is drawing only ONE(last) curve. Dear fellowship, please help !


    Qt Code:
    1. Plot::Plot()
    2. {
    3. setTitle("A Simple QwtPlot Demonstration");
    4. insertLegend(new QwtLegend(), QwtPlot::RightLegend);
    5.  
    6. // Set axis titles
    7. setAxisTitle(xBottom, "x -->");
    8. setAxisTitle(yLeft, "y -->");
    9.  
    10. // Insert new curves
    11. QwtPlotCurve *cSin = new QwtPlotCurve("y = sin(x)");
    12. #if QT_VERSION >= 0x040000
    13. cSin->setRenderHint(QwtPlotItem::RenderAntialiased);
    14. #endif
    15. cSin->setPen(QPen(Qt::red));
    16. cSin->attach(this);
    17.  
    18. const int nPoints = 100;
    19. double x[2][nPoints], y[2][nPoints];
    20. for(int j=0; j<2; j++)
    21. {
    22. for(int i=0; i<nPoints; i++)
    23. {
    24. x[j][i] = -3.14 + i*(j+2)*3.14/(nPoints-1);
    25. y[j][i] = sin((j+1)*x[j][i]);
    26. }
    27. }
    28.  
    29. // Create 2d array data
    30. for(int j=0; j<2; j++)
    31. cSin->setData(x[j],y[j],nPoints);
    32.  
    33. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by kahramonj; 18th March 2009 at 19:30.

  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: 2D array data plot!

    Quote Originally Posted by kahramonj View Post
    I'd like to draw 2d array data and it is my first experience with QWT, everything is OK, but the following code is drawing only ONE(last) curve.
    Not surprising, because in your code is only one curve. The second setData call changes the points of the curve, but doesn't create a second one.

    Instead you need to attach 2 different QwtPlotCurve objects - one for each array.

    Uwe

  3. The following user says thank you to Uwe for this useful post:

    kahramonj (19th March 2009)

  4. #3
    Join Date
    Mar 2009
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: 2D array data plot!

    Quote Originally Posted by Uwe View Post
    Not surprising, because in your code is only one curve. The second setData call changes the points of the curve, but doesn't create a second one.

    Instead you need to attach 2 different QwtPlotCurve objects - one for each array.

    Uwe
    Thanks, I think the problem is solved, the changed code:

    Qt Code:
    1. Plot::Plot()
    2. {
    3. setTitle("A Simple QwtPlot Demonstration");
    4. insertLegend(new QwtLegend(), QwtPlot::RightLegend);
    5.  
    6. // Set axis titles
    7. setAxisTitle(xBottom, "x -->");
    8. setAxisTitle(yLeft, "y -->");
    9.  
    10. // Insert new curves
    11. QwtPlotCurve **cSin;
    12. cSin= new QwtPlotCurve* [2]; //("y = sin(x)");
    13. for(int j=0; j<2; j++)
    14. {
    15. cSin[j]=new QwtPlotCurve;
    16. #if QT_VERSION >= 0x040000
    17. cSin[j]->setRenderHint(QwtPlotItem::RenderAntialiased);
    18. #endif
    19. cSin[j]->setPen(QPen(Qt::red));
    20. cSin[j]->attach(this);
    21. }
    22.  
    23. const int nPoints = 100;
    24. double x[2][nPoints], y[2][nPoints];
    25. for(int j=0; j<2; j++)
    26. {
    27. for(int i=0; i<nPoints; i++)
    28. {
    29. x[j][i] = -3.14 + i*(j+2)*3.14/(nPoints-1);
    30. y[j][i] = sin((j+1)*x[j][i]);
    31. }
    32. }
    33.  
    34. // Create 2d array data
    35. for(int j=0; j<2; j++)
    36. cSin[j]->setData(x[j],y[j],nPoints);
    37.  
    38. }
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Mar 2009
    Posts
    6
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: 2D array data plot!

    hi,

    can u plz tell me how to take data from a .txt file and plot the same?

    thanks u so much 4r ur help

Similar Threads

  1. Replies: 12
    Last Post: 31st October 2010, 18:08
  2. Spectrogram Plot Hints
    By shargath in forum Qwt
    Replies: 2
    Last Post: 25th February 2009, 12:11
  3. Using a 2d data array to create an image
    By dbrmik in forum Newbie
    Replies: 20
    Last Post: 28th October 2008, 18:22
  4. Replies: 15
    Last Post: 27th May 2008, 02:46
  5. Creating a Pixmap out of an array of data
    By toratora in forum Qt Programming
    Replies: 2
    Last Post: 5th June 2007, 20:00

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.