PDA

View Full Version : QVectors plotting



Hanafy
30th September 2015, 10:43
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 ;

d_stranz
30th September 2015, 16:28
I assume you are using QCustomPlot (http://www.qcustomplot.com/) 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?