首页 > 其他分享 >qcustomplot 绘图 3

qcustomplot 绘图 3

时间:2023-06-17 12:11:52浏览次数:33  
标签:plot graph 180 qcustomplot pen 绘图 errorBars xAxis

内容:包络线(填充),散点图,线型,errorBar等

不同坐标的显示技巧:1、设置不同的x轴,2、QCPErrorBars 特有的 setDataPlottable(...);

    plot->legend->setVisible(true);
    plot->legend->setFont(QFont("Helvetica",9));
    // set locale to english, so we get english decimal separator:
    plot->setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom));
    // add confidence band graphs:
    plot->addGraph();
    QPen pen;
    pen.setStyle(Qt::DotLine);
    pen.setWidth(1);
    pen.setColor(QColor(180,180,180));
    plot->graph(0)->setName("Confidence Band 68%");
    plot->graph(0)->setPen(pen);
    plot->graph(0)->setBrush(QBrush(QColor(255,50,30,20)));
    plot->addGraph();    
    plot->legend->removeItem(plot->legend->itemCount()-1); // don't show two confidence band graphs in legend
    plot->graph(1)->setPen(pen);
    plot->graph(0)->setChannelFillGraph(plot->graph(1));
    // add theory curve graph:
    plot->addGraph();
    pen.setStyle(Qt::DashLine);
    pen.setWidth(2);
    pen.setColor(Qt::red);
    plot->graph(2)->setPen(pen);
    plot->graph(2)->setName("Theory Curve");
    // add data point graph:
    plot->addGraph();
    plot->graph(3)->setPen(QPen(Qt::blue));
    plot->graph(3)->setName("Measurement");
    plot->graph(3)->setLineStyle(QCPGraph::lsNone);
    plot->graph(3)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCross, 4));
    // add error bars:
    QCPErrorBars *errorBars = new QCPErrorBars(plot->xAxis, plot->yAxis);
    errorBars->removeFromLegend();
    errorBars->setAntialiased(false);
    errorBars->setDataPlottable(plot->graph(3));
    errorBars->setPen(QPen(QColor(180,180,180)));

    // generate ideal sinc curve data and some randomly perturbed data for scatter plot:
    QVector<double> x0(250), y0(250);
    QVector<double> yConfUpper(250), yConfLower(250);
    for (int i=0; i<250; ++i)
    {
        x0[i] = (i/249.0-0.5)*30+0.01; // by adding a small offset we make sure not do divide by zero in next code line
        y0[i] = qSin(x0[i])/x0[i]; // sinc function
        yConfUpper[i] = y0[i]+0.15;
        yConfLower[i] = y0[i]-0.15;
        x0[i] *= 1000;
    }
    QVector<double> x1(50), y1(50), y1err(50);
    for (int i=0; i<50; ++i)
    {
        // generate a gaussian distributed random number:
        double tmp1 = rand()/(double)RAND_MAX;
        double tmp2 = rand()/(double)RAND_MAX;
        double r = qSqrt(-2*qLn(tmp1))*qCos(2*M_PI*tmp2); // box-muller transform for gaussian distribution
        // set y1 to value of y0 plus a random gaussian pertubation:
        x1[i] = (i/50.0-0.5)*30+0.25;
        y1[i] = qSin(x1[i])/x1[i]+r*0.15;
        x1[i] *= 1000;
        y1err[i] = 0.15;
    }
    // pass data to graphs and let QCustomPlot determine the axes ranges so the whole thing is visible:
    plot->graph(0)->setData(x0, yConfUpper);
    plot->graph(1)->setData(x0, yConfLower);
    plot->graph(2)->setData(x0, y0);
    plot->graph(3)->setData(x1, y1);
    errorBars->setData(y1err);
    plot->graph(2)->rescaleAxes();
    plot->graph(3)->rescaleAxes(true);
    // setup look of bottom tick labels:
    plot->xAxis->setTickLabelRotation(30);
    plot->xAxis->ticker()->setTickCount(9);
    plot->xAxis->setNumberFormat("ebc");
    plot->xAxis->setNumberPrecision(1);
    plot->xAxis->moveRange(-10);
    // make top right axes clones of bottom left axes. Looks prettier:
    plot->axisRect()->setupFullAxesBox();

 

标签:plot,graph,180,qcustomplot,pen,绘图,errorBars,xAxis
From: https://www.cnblogs.com/kingkaixuan/p/17487310.html

相关文章

  •  qcustomplot 绘图 1
    周末,闲读,翻翻qcustomplot例子。以前用qchart,实在无法接收这个类的低效。打开qchart,仿佛在推一个滞重的铁门。qcustomplot感觉轻快灵动。1.准备CMakeLists.txtcmake_minimum_required(VERSION3.5)project(plot_0VERSION0.1LANGUAGESCXX)set(CMAKE_AUTOUICON)......
  • qcustomplot 绘图 2
    这个例子涉及:双坐标,坐标联动、坐标自适应、多线绘制,图形填充,图形缩放plot->addGraph();plot->graph(0)->setPen(QPen(Qt::blue));//linecolorblueforfirstgraphplot->graph(0)->setBrush(QBrush(QColor(0,0,255,20)));//firstgraphwillbefilledw......
  • Altair绘图自学成材
    目录1。Altair介绍(全名:Vega-Altair)2。一步一步学画图3。样例一个用自定义图标显示在坐标轴里的图形1。Altair介绍(全名:Vega-Altair)它是一个专为Python编写的可视化软件包,它能让数据科学家更多地关注数据本身和其内在的联系。https://github.com/altair-viz/altair安装:Vega-Alta......
  • 实验6 turtle绘图与python库应用编程体验
    实验任务1fromturtleimport*defmove(x,y):'''画笔移动到坐标(x,y)处'''penup()goto(x,y)pendown()defdraw(n,size=100):'''绘制边长为size的正n边形'''foriinrange(n):fd(siz......
  • Python 绘图 colorbar 隐藏刻度保留标签 (颜色刻度 和标签刻度 两个)
      ax3=fig.add_axes(config['setpng']['colorbar'])#四个参数分别是左、下、宽、长  cb3=mpl.colorbar.ColorbarBase(ax3,cmap=_cmap,norm=norm)  #set_colorbar_ticks(cb3,levels,config['levels']['wind_s_label'])#色标刻度调整  ......
  • 实验6 turtle绘图与python库应用编程体验
    实验任务1task1-11fromturtleimport*2defmove(x,y):3penup()4goto(x,y)5pendown()6defdraw(n,size=100):7foriinrange(n):8fd(size)9left(360/n)10defmain():11pensize(2)12pencolor(......
  • 实验6 turtle绘图与python库应用编程体验
    task1-1源代码1fromturtleimport*23defmove(x,y):4'''画笔移动到坐标(x,y)处'''5penup()6goto(x,y)7pendown()89defdraw(n,size=100):10'''绘制边长为size的正n变形'''1......
  • 实验6 turtle绘图与Python库应用编程体验
    task1-1.py实验源码:fromturtleimport*defmove(x,y):penup()goto(x,y)pendown()defdraw(n,size=100):foriinrange(n):fd(size)left(360/n)defmain():pensize(2)pencolor('red')move(-200,0)......
  • 实验6 turtle绘图与python库应用编程体验
    task1_1代码:fromturtleimport*defmove(x,y):'''画笔移动到坐标(x,y)处'''penup()goto(x,y)pendown()defdraw(n,size=100):'''绘制边长为size的正n变形'''foriinrange(n):......
  • 实验6 turtle绘图与python库应用编程体验
    实验任务1task1_1.py程序源码:1fromturtleimport*23defmove(x,y):#画笔移动到坐标(x,y)处4penup()5goto(x,y)6pendown()78defdraw(n,size=100):#绘制边长为size的正n变形9foriinrange(n):10forward(size)11......