0

我想用 qcustomplot 在离散点绘制两个函数之间的残差。

我知道位置 (x)、起始值 y.at(x) 和 height.at(x)。

到目前为止,我有一个带有 y+-error 的错误栏:

QCPErrorBars *errorBars = new QCPErrorBars(customPlot->xAxis, customPlot->yAxis);
errorBars->setDataPlottable(customPlot->graph(0));
QVector<double> y1err(x.size());
for (int i = 0; i<x.size(); ++i)
{
    y1err[i] = y.at(i) * error;
}
customPlot->graph(0)->setData(QVector<double>::fromStdVector(x), QVector<double>::fromStdVector(y));
errorBars->setData(y1err);

或从零开始的条形图:

QCPBars *newBars = new QCPBars(customPlot->xAxis, customPlot->yAxis);
std::vector<double> xData, yData;
for (auto i = 0; i < x.size(); ++i)
{
    xData.push_back(i+1);
    yData.push_back(y.at(i));
}
newBars->setData(QVector<double>::fromStdVector(x), QVector<double>::fromStdVector(y));

但我真正想要的是某种从 y.at(x) 值开始的图,除了两个 xy 图之外,还有点 x 处的残差高度。如何使用 height.at(x) 从 y.at(x) 开始绘制条形图或误差线?

谢谢

4

1 回答 1

0

对于面临这个问题的其他人,我找到了某种解决方案。

void QLinePlot::AddResiduumData(std::vector<double> x, std::vector<double> y_mid, std::vector<double> y_res)
{
customPlot->addGraph();
++graphCountI;

QCPErrorBars *errorBars = new QCPErrorBars(customPlot->xAxis, customPlot->yAxis);
errorBars->setDataPlottable(customPlot->graph(graphCountI - 1));
customPlot->graph(graphCountI - 1)->setData(QVector<double>::fromStdVector(x), QVector<double>::fromStdVector(y_mid));
customPlot->graph(graphCountI - 1)->setVisible(false);
errorBars->setData(QVector<double>::fromStdVector(y_res));
customPlot->replot();
}

这背后的想法是在两个图之间添加一个新的不可见图形,并将误差作为两者之间距离的一半。

于 2016-11-16T09:32:33.450 回答