Qt-QCustomPlot绘制图

Qt-QCustomPlot绘制图,qt,graph,qcustomplot,Qt,Graph,Qcustomplot,我在QCustomPlot库中绘制图形时遇到问题。我想画一个对数图,但我用的是区间图。因为对数不是从-3到0定义的,所以在这个间隔上画图时我什么也不做 我有以下代码: QVector<double> x(10001), y(10001); QVector<double> x1(10001), y1(10001); double t=-3; //cas double inkrement = 0.0006; for (int i=0; i<10001; i++)//k

我在QCustomPlot库中绘制图形时遇到问题。我想画一个对数图,但我用的是区间图。因为对数不是从-3到0定义的,所以在这个间隔上画图时我什么也不做

我有以下代码:

QVector<double> x(10001), y(10001);
QVector<double> x1(10001), y1(10001);

double t=-3; //cas
double inkrement = 0.0006;
for (int i=0; i<10001; i++)//kvadraticka funkcia
{
  x[i] = t;
  y[i] = (-1)*t*t-2;
  t+=inkrement;
}

int g=0;
for(double l=-3;l<3; l+=inkrement) {
   if(l<=0.0) continue;
   else {
   //QMessageBox::warning(this, tr("note"), tr("l=%1\n").arg(l), QMessageBox::Ok);
   x1[g] = l;
   y1[g] = log10(l)/log10(exp(1.0));
   //QMessageBox::warning(this, tr("note"), tr("x1=%1\ny1=%2").arg(x1[g]).arg(y1[g]), QMessageBox::Ok);
   //break;
   g++;
   }
}

customPlot->addGraph();
customPlot->graph(0)->setData(x, y);

customPlot->addGraph();
customPlot->graph(1)->setData(x1, y1);

customPlot->xAxis->setLabel("x");
customPlot->yAxis->setLabel("y");

customPlot->xAxis->setRange(-3, 3);
customPlot->yAxis->setRange(-10, 5);
customPlot->replot();
qx(10001),y(10001);
qx1(10001),y1(10001);
双t=-3//中科院
双墨水量=0.0006;
对于(int i=0;等时数据(x,y);
customPlot->addGraph();
自定义绘图->图形(1)->设置数据(x1,y1);
customPlot->xAxis->setLabel(“x”);
customPlot->yAxis->setLabel(“y”);
customPlot->xAxis->setRange(-3,3);
customPlot->yAxis->setRange(-10,5);
customPlot->replot();
其中x1和y1是QVectors…但是这个图就像第一个点在[0,0]中一样。所以我有一条线连接点[0,0]和对数图,我不知道为什么:(
当我在循环前设置l=0.0006时,一切正常。你能帮我吗?

似乎你在循环前设置了x1和y1的计数。QVector用零初始化。因此,如果你没有为某些项目设置任何值,那么
x1
y1
将在它们的末尾包含零值

如果g正常,则应使用空QVector并添加新值:

QVector<double> x1, y1;
//...
x1 << l;
y1 << log10(l)/log10(exp(1.0));
qx1,y1矢量;
//...

x1似乎在循环之前设置了x1和y1的计数。QVector用零初始化。因此,如果您没有为某些项目设置任何值,那么
x1
y1
将在其末尾包含零值

如果g正常,则应使用空QVector并添加新值:

QVector<double> x1, y1;
//...
x1 << l;
y1 << log10(l)/log10(exp(1.0));
qx1,y1矢量;
//...
x1谢谢:)接线员谢谢:)接线员