QCustomPlot Discussion and Comments

bug with swap axisReturn to overview

I am try to swap axis from example:


demoName = "Quadratic Demo";
// generate some data:
QVector<double> x(101), y(101); // initialize with entries 0..100
for (int i=0; i<101; ++i)
{
  x[i] = i/50.0 - 1; // x goes from -1 to 1
  y[i] = x[i]*x[i];  // let's plot a quadratic function
}
// create graph and assign data to it:
customPlot->addGraph();
customPlot->graph(0)->setData(y, x);
// give the axes some labels:
customPlot->yAxis->setLabel("x");
customPlot->xAxis->setLabel("y");
// set axes ranges, so we see all data:
customPlot->yAxis->setRange(-1, 1);
customPlot->xAxis->setRange(0, 1);


and get wrong output.
The reason for this maybe QMap, which internally used for store data.
This bug is in all versions of QCustomPlot. Please fix it...

It is not bug

"Graphs are used to display single-valued data. Single-valued means that there should only be one data point per unique key coordinate. In other words, the graph can't have loops. If you do want to plot non-single-valued curves, rather use the QCPCurve plottable."

If you want to swap the axes for a graph (such that the keys are on the yAxis and the values on the xAxis), you should specify the key/value axes upon construction of the graph:

customPlot->addGraph(customPlot->yAxis, customPlot->xAxis);

See documentation for details.

Other than that, VforCtrlV is correct if you intend to have a curve instead of a graph.