c++ - How to draw graph for a trajectory which goes left and right in x axis?
问题描述
i want to draw a trajectory in x and y of a car in a parking lot.
the trajectory in x is not always in the same direction. sometime the car will go left.
the problem here is: sometime (not always!) the graph will no go left in x axis. You can see the two different result on the image https://imgur.com/Z53fNkt
any idea why?
the image at left is what i expect. at right is the same values , but i continue to plot data a little longer.
void TrackingResultsView::setupTrajectoryPlot()
{
QCustomPlot *customPlot = ui->qcp_trajectory;
customPlot->xAxis2->setVisible(true);
customPlot->xAxis2->setLabel("X-Position (pixel)");
customPlot->xAxis2->setRange(0, mModelPtr->frameSize().width());
customPlot->xAxis2->grid()->setVisible(true);
customPlot->xAxis->setRange(0, mModelPtr->frameSize().width());
customPlot->yAxis->setLabel("Y-Position (pixel)");
customPlot->yAxis->setRange(0, mModelPtr->frameSize().height());
customPlot->yAxis->setRangeReversed(true);
customPlot->yAxis2->setVisible(true);
customPlot->yAxis2->setRange(0, mModelPtr->frameSize().height());
customPlot->yAxis2->grid()->setVisible(true);
customPlot->yAxis2->setRangeReversed(true);
customPlot->addGraph(customPlot->xAxis2, customPlot->yAxis);
QVector<QVector<double>> data = createDataMap(mModelPtr->points());
customPlot->graph()->setData(data.at(0), data.at(1), true);
setTheme(customPlot, false);
}
thank you
(english is not my first langage)
解决方案
The QCPGraph
seems to be used for sorted data with only value per key. From QCustomPlot documentation, it looks like the QCPCurve would be a better match in order to plot a trajectory graph (multiple value for the same key).
From the QCPCurve
description:
Unlike QCPGraph, plottables of this type may have multiple points with the same key coordinate, so their visual representation can have loops. This is realized by introducing a third coordinate t, which defines the order of the points described by the other two coordinates x and y.
推荐阅读
- jmeter - BlazeMeter - 从 Jmeter 中的 beanshell 读取 CVS 文件
- python - 元素(按钮)无法滚动到视图中
- docker - 使用 yaml 文件将 Docker 容器部署到 Kubernetes
- python - Pandas 选择多个属于最终日期的指数
- arm - arm neon inline assemble“mov”clang和gcc的区别
- c# - 我想使用 jquery 将行插入 WebGrid
- c++ - OpenCV 球面投影:翘曲和反翘曲
- javascript - 使用身份验证发布 Ajax:401(未经授权)
- typescript - 将输入参数约束为某个泛型类型的超类型,并使结果类型为同一类型
- matlab - 如何绘制以质心为中心的某个像素区域的正方形