Results 1 to 7 of 7

Thread: how to load data file and plot from the datafile

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

    Default how to load data file and plot from the datafile

    hi
    I am charu, totally New to Qwt , i have to plot from .txt file containing floating point. i want to know how to load/read a datafile and plot it row by row (that is: one value by one)
    thank you for ur grt help

  2. #2
    Join Date
    Mar 2009
    Posts
    22
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to load data file and plot from the datafile

    Quote Originally Posted by charu View Post
    hi
    I am charu, totally New to Qwt , i have to plot from .txt file containing floating point. i want to know how to load/read a datafile and plot it row by row (that is: one value by one)
    thank you for ur grt help
    Hi charu,
    I also new. I wrote something similar to load data from text file:
    Qt Code:
    1. QFile file("./data.txt");
    2. if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
    3. return;
    4. QTextStream in(&file);
    5. while (!in.atEnd()) {
    6. list << in.readLine();
    7. }
    8. data = new double[list.size()];
    9. for(int i = 0; i< list.size(); i++){
    10. data[i] = list[i].toDouble();
    11. }
    12. dataSize = list.size();
    To copy to clipboard, switch view to plain text mode 

    And the data.txt in this format:
    1.8600000e+03
    1.8640000e+03
    1.8660000e+03
    1.8550000e+03
    1.8660000e+03
    1.8760000e+03
    For plotting, you can look at the examples (simple plot maybe).
    Good luck.


    Hüseyin

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

    charu (23rd March 2009)

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

    Default Re: how to load data file and plot from the datafile

    thank you so much

    Now i need to Plot the data ?
    can u plz tell me how to plot? I am using QT3 and QWT5.1.1

  5. #4
    Join Date
    Mar 2009
    Posts
    22
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to load data file and plot from the datafile

    Quote Originally Posted by charu View Post
    thank you so much

    Now i need to Plot the data ?
    can u plz tell me how to plot? I am using QT3 and QWT5.1.1
    Sorry, I don't have Qt3.
    Also I don't know the difference between 3 and 4.
    Maybe both are same for simple things.

    For plotting I am using double array, and QwtPlotCurve::setRawData() in a derived QwtPlot class.

    You can also use setData().
    Simply like this: (From QwtPlot Class Reference)
    Qt Code:
    1. #include <qwt_plot.h>
    2. #include <qwt_plot_curve.h>
    3.  
    4. QwtPlot *myPlot;
    5. double x[100], y1[100], y2[100]; // x and y values
    6.  
    7. myPlot = new QwtPlot("Two Curves", parent);
    8.  
    9. // add curves
    10. QwtPlotCurve *curve1 = new QwtPlotCurve("Curve 1");
    11. QwtPlotCurve *curve2 = new QwtPlotCurve("Curve 2");
    12.  
    13. getSomeValues(x, y1, y2);
    14.  
    15. // copy the data into the curves
    16. curve1->setData(x, y1, 100);
    17. curve2->setData(x, y2, 100);
    18.  
    19. curve1->attach(myPlot);
    20. curve2->attach(myPlot);
    21.  
    22. // finally, refresh the plot
    23. myPlot->replot();
    To copy to clipboard, switch view to plain text mode 

    In getSomeValues(x, y1, y2) simply copy the data to the double buffers.


    Hüseyin

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

    Default Re: how to load data file and plot from the datafile

    thanks

    i have error:expected constructor,destructor, or type conversion before'=' token..... hence i commented each line by line
    1) no errors with include file alone
    2) error started from myplot=... onwards .
    i dont have any idea to solve this can you plz let me know what could be the problem on my program.

    procedure i created the project:
    1) New Project
    2) New Widget
    3) New main.cpp
    copied ur code in the form1.ui.h and qmake, make ....errors plz help me

    thank u in advance

  7. #6
    Join Date
    Mar 2009
    Posts
    22
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to load data file and plot from the datafile

    Quote Originally Posted by charu View Post
    thanks

    i have error:expected constructor,destructor, or type conversion before'=' token..... hence i commented each line by line
    1) no errors with include file alone
    2) error started from myplot=... onwards .
    i dont have any idea to solve this can you plz let me know what could be the problem on my program.

    procedure i created the project:
    1) New Project
    2) New Widget
    3) New main.cpp
    copied ur code in the form1.ui.h and qmake, make ....errors plz help me

    thank u in advance
    It could be many different things; maybe header problem, or trying to reach a pointer out of scope....I don't know.
    Now, its your turn to figure it out.
    Act like a detective, and find the problem. Maybe you should turn back to some fundamentals.

    Good luck.


    Hüseyin

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

    Default Re: how to load data file and plot from the datafile

    thanks i got it

    After incliding the lib file i can plot.

    but the getSomeValues(); is not working, so i generated some x,y values and ploted

    thank you so much 4r ur grt help

Similar Threads

  1. Replies: 12
    Last Post: 31st October 2010, 17:08
  2. Qwt plot + grid huge pdf file
    By giusepped in forum Qwt
    Replies: 3
    Last Post: 17th December 2008, 13:53

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.