第一次写——坐标趋势图

第一次写——坐标趋势图

void keyevent::qst(){
QCustomPlot *pCustomPlot = new QCustomPlot(this);
//pCustomPlot->resize(300, 300);
pCustomPlot->setGeometry(200,200,300,300
//ui.horizontalLayout->addWidget(pCustomPlot);
// 可变数组存放绘图的坐标的数据,分别存放x和y坐标的数据,101为数据长度
QVector<double> x(101), y(101);

// 添加数据,这里演示y = x^3,为了正负对称,x从-10到+10
for (int i = 0; i < 101; ++i)
{
    if (i < 30)
    {
        x[i] = i / 5 - 10;
        y[i] = qPow(x[i], 3);  // x的y次方;
    }
    else {

        x[i] = i + 3;
        y[i] = i * 8;
    }
}
// 向绘图区域QCustomPlot添加一条曲线
QCPGraph *pGraph = pCustomPlot->addGraph();

// 添加数据
pCustomPlot->graph(0)->setData(x, y);

// 设置坐标轴名称
pCustomPlot->xAxis->setLabel("x");
pCustomPlot->yAxis->setLabel("y");

// 设置背景色
pCustomPlot->setBackground(QColor(50, 50, 50));

pGraph->setPen(QPen(QColor(32, 178, 170)));

// 设置x/y轴文本色、轴线色、字体等
pCustomPlot->xAxis->setTickLabelColor(Qt::blue);
pCustomPlot->xAxis->setLabelColor(QColor(0, 160, 230));
pCustomPlot->xAxis->setBasePen(QPen(QColor(32, 178, 170)));
pCustomPlot->xAxis->setTickPen(QPen(QColor(128, 0, 255)));
pCustomPlot->xAxis->setSubTickPen(QColor(255, 165, 0));
QFont xFont = pCustomPlot->xAxis->labelFont();
xFont.setPixelSize(20);
pCustomPlot->xAxis->setLabelFont(xFont);

pCustomPlot->yAxis->setTickLabelColor(Qt::white);
pCustomPlot->yAxis->setLabelColor(QColor(0, 160, 230));
pCustomPlot->yAxis->setBasePen(QPen(QColor(32, 178, 170)));
pCustomPlot->yAxis->setTickPen(QPen(QColor(128, 0, 255)));
pCustomPlot->yAxis->setSubTickPen(QColor(255, 165, 0));
QFont yFont = pCustomPlot->yAxis->labelFont();
yFont.setPixelSize(20);
pCustomPlot->yAxis->setLabelFont(yFont);

// 设置坐标轴显示范围,否则只能看到默认范围
pCustomPlot->xAxis->setRange(0, 30);
pCustomPlot->yAxis->setRange(-1100, 1100);

}

转载于:https://blog.51cto.com/12892173/2124659

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值