Results 1 to 2 of 2

Thread: QVectors plotting

  1. #1
    Join Date
    Sep 2015
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default QVectors plotting

    Hi Everyone,

    my code has two vectors and i would like to plot them as x-y plot but nothing is appears for me at the widget and i do not have any error during compilation.

    my code is

    \code
    // generate some data

    QVector<double> x= QVector<double>::fromStdVector(thetas);
    QVector<double> y= QVector<double>::fromStdVector(us);

    // create graph and assign data to it:
    ui->customPlot->addGraph();
    ui->customPlot->graph(0)->setData(x, y);
    // give the axes some labels:
    ui->customPlot->xAxis->setLabel("thetas [degree]");
    ui->customPlot->yAxis->setLabel("Scalar Stator Magnetic Pontential [Vs/m]");
    // set axes ranges, so we see all data:
    ui->customPlot->xAxis->setRange(0, 360);
    ui->customPlot->yAxis->setRange(-500, 500);
    ui->customPlot->replot();
    //cout << thetas[jj] << endl ;

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QVectors plotting

    I assume you are using QCustomPlot since your code is almost exactly the same as the example posted at that site. So, if their code works, then yours should too.

    - What do you see if you call addGraph() but do not call setData()? Do you see an empty plot? Do you see anything at all?
    - Are you sure that your data has the ranges you are setting for the axes?
    - Are both vectors the same size?
    - Have you looked at the contents of the QVector<double> and the std::vector<double>? Are they what you expect?

Similar Threads

  1. plotting 2d in qt
    By buzzz321 in forum Newbie
    Replies: 7
    Last Post: 13th July 2012, 08:56
  2. Read binary file into 2 QVectors
    By juracist in forum Qt Programming
    Replies: 6
    Last Post: 20th May 2012, 00:35
  3. extracting QVectors from a multidimensional QVEctor array
    By OzQTNoob in forum Qt Programming
    Replies: 2
    Last Post: 23rd February 2012, 07:45
  4. Replies: 2
    Last Post: 17th May 2011, 10:47
  5. Plotting in 3D
    By FelixB in forum Qwt
    Replies: 1
    Last Post: 1st October 2010, 16:26

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.