Results 1 to 5 of 5

Thread: Plot x^2 curve

  1. #1
    Join Date
    May 2012
    Posts
    99
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question Plot x^2 curve

    Hi all,

    I have this code to plot the x^2 curve:

    Qt Code:
    1. // add curves
    2. QwtPlotCurve *curve1 = new QwtPlotCurve("Graph 1");
    3.  
    4. //set curve color
    5. curve1->setPen(QPen(Qt::red, 2));
    6.  
    7. // add curves
    8. curve1->attach(ui->qwtPlotWidget);
    9.  
    10. const int MAX_VALUES = 100;
    11. double x[2*MAX_VALUES], y1[2*MAX_VALUES];// x and y values
    12. for (int i (-MAX_VALUES); i < MAX_VALUES; i++)
    13. {
    14. x[i] = i;
    15. y1[i] = i*i;
    16. }
    17.  
    18. // copy the data into the curves
    19. curve1->setSamples(x, y1, 2*MAX_VALUES);
    20.  
    21. // finally, refresh the plot
    22. ui->qwtPlotWidget->replot();
    To copy to clipboard, switch view to plain text mode 

    But I get this strange plot:


    What's wrong?

    Regards.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Plot x^2 curve

    You are definitely missing "=" in line #12. x[-100..-1] and y[-100..-1] likely point to some garbage as well.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2012
    Posts
    99
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Plot x^2 curve

    Can you put the right code please?

    Regards.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Plot x^2 curve

    Qt Code:
    1. for(int i=0;i<MAX_VALUES*2;++i) {
    2. x[i] = -MAX_VALUES+i;
    3. y1[i] = x[i]*x[i];
    4. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    May 2012
    Posts
    99
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Plot x^2 curve

    Thank you!

Similar Threads

  1. [Qwt] selection of curve/plot/...
    By packman2012 in forum Qt-based Software
    Replies: 0
    Last Post: 5th April 2012, 09:39
  2. getting attached curve to a plot
    By corrado1972 in forum Qwt
    Replies: 2
    Last Post: 22nd June 2011, 09:35
  3. detach only one qwt plot curve?
    By kja in forum Qwt
    Replies: 1
    Last Post: 3rd December 2010, 07:54
  4. How to plot tan(x) curve?
    By Name in forum Qwt
    Replies: 1
    Last Post: 17th September 2010, 13:20
  5. Replies: 2
    Last Post: 8th January 2010, 14:09

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.