绘制箭头图

环境:qt5.14.2 ,mingw,qcustomplot

功能:完成绘制箭头图,且当y为负的时候让三角形朝下。对原始数据进行了拆分,分别存入不同的容器中。然后分别设置样式。

结果展示:

代码:

struct GraphInfo
{
    QVector<double> x;       
    QVector<double> y;      
    QColor penColor=Qt::red;
};
void Widget::createChart()
{

    QList<GraphInfo> listInfo;
    listInfo.append(graph1);
    listInfo.append(graph2);
    listInfo.append(graph3);

    QCPScatterStyle positiveStyle(QCPScatterStyle::ssTriangle, 7);
    QCPScatterStyle negativeStyle(QCPScatterStyle::ssTriangleInverted, 7);

    for (GraphInfo &info : listInfo)
    {
        QVector<double> x_positive, y_positive;
        QVector<double> x_negative, y_negative;

        for (int i = 0; i < info.y.size(); ++i)
        {
            if (info.y[i] >= 0)
            {
                x_positive.append(info.x[i]);
                y_positive.append(info.y[i]);
            }
            else
            {
                x_negative.append(info.x[i]);
                y_negative.append(info.y[i]);
            }
        }

        // Add positive graph
        customPlot->addGraph();
        customPlot->graph()->setPen(info.penColor);

        customPlot->graph()->setLineStyle(QCPGraph::lsImpulse);
        positiveStyle.setBrush(info.penColor);
        customPlot->graph()->setScatterStyle(positiveStyle);
        customPlot->graph()->setData(x_positive, y_positive);

        // Add negative graph
        customPlot->addGraph();
        customPlot->graph()->setPen(info.penColor);

        customPlot->graph()->setLineStyle(QCPGraph::lsImpulse);
        negativeStyle.setBrush(info.penColor);
        customPlot->graph()->setScatterStyle(negativeStyle);
        customPlot->graph()->setData(x_negative, y_negative);
    }

    customPlot->xAxis->setTicks(true);
    customPlot->yAxis->setTicks(true);
    customPlot->xAxis->setTickLabels(true);
    customPlot->yAxis->setTickLabels(true);

    customPlot->legend->setVisible(false);
    customPlot->legend->setFont(QFont("Helvetica", 9));
    customPlot->axisRect()->setupFullAxesBox();
    customPlot->rescaleAxes();

    customPlot->replot();
}

全部评论

相关推荐

求offer的大角牛:不吃香菜
点赞 评论 收藏
分享
Southyeung:我说一下我的看法(有冒犯实属抱歉):(1)简历不太美观,给我一种看都不想看的感觉,感觉字体还是排版问题;(2)numpy就一个基础包,机器学习算法是什么鬼?我感觉你把svm那些写上去都要好一点。(2)课程不要写,没人看,换成获奖经历;(3)项目太少了,至少2-3个,是在不行把网上学习的也写上去。
点赞 评论 收藏
分享
今天投了小鹏,收到了AI面,大概会问哪些啊?
期末一定及格:总共4个部分,心理测评、行测、然后就是问岗位、对岗位的理解、过往遇到了哪些难点怎么解决,很简单,没有什么特别专业的问题,都是一些综合素质相关的
小鹏汽车AI面7人在聊
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务