QCustomPlot Discussion and Comments

Graph dips at 0 how to avoid this?Return to overview

   ui->w1->xAxis->setRange(-5,5);
   ui->w1->yAxis->setRange(0,5);

   QVector<double>a(11),b(11);
a<<0<<1<<2<<3<<4<<4<<4<<3<<2<<1<<0;
b<<-5<<-4<<-3<<-2<<-1<<0<<1<<2<<3<<4<<5;
ui->w1->addGraph(ui->w1->xAxis,ui->w1->yAxis);
ui->w1->graph(0)->setData(b,a);

We cant see point (0,5) the graph dips to Zero and we get straight line on y axis of value 5 units then on positive side it starts from zero instead of 5.
how to improve/avoid this?

I think you are misunderstanding the constructor of QVector that you're using:
https://doc.qt.io/qt-5/qvector.html#QVector-1
QVector a(11); creates 11 pre-existing elements with value 0. With the operator<< you just add more elements. So the dip at 0 are those 11 elements you have in there. Try not using that constructor in your case (maybe you wanted to use QVector::reserve instead, but with 11 elements it's truly not needed)