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

qcustomplot 绘图 2

时间:2023-06-17 11:45:12浏览次数:34  
标签:plot graph qcustomplot ranges 绘图 y1 y0 QCPRange

这个例子涉及:双坐标,坐标联动、坐标自适应、多线绘制,图形填充,图形缩放

    plot->addGraph();
    plot->graph(0)->setPen(QPen(Qt::blue)); // line color blue for first graph
    plot->graph(0)->setBrush(QBrush(QColor(0, 0, 255, 20))); // first graph will be filled with translucent blue
    plot->addGraph();
    plot->graph(1)->setPen(QPen(Qt::red)); // line color red for second graph
    // generate some points of data (y0 for first, y1 for second graph):
    QVector<double> x(251), y0(251), y1(251);
    for (int i=0; i<251; ++i)
    {
        x[i] = i;
        y0[i] = qExp(-i/150.0)*qCos(i/10.0); // exponentially decaying cosine
        y1[i] = qExp(-i/150.0);              // exponential envelope
    }
    // configure right and top axis to show ticks but no labels:
    // (see QCPAxisRect::setupFullAxesBox for a quicker method to do this)
    plot->xAxis2->setVisible(true);
    plot->xAxis2->setTickLabels(false);
    plot->yAxis2->setVisible(true);
    plot->yAxis2->setTickLabels(false);
    // make left and bottom axes always transfer their ranges to right and top axes:
    connect(plot->xAxis, SIGNAL(rangeChanged(QCPRange)), plot->xAxis2, SLOT(setRange(QCPRange)));
    connect(plot->yAxis, SIGNAL(rangeChanged(QCPRange)), plot->yAxis2, SLOT(setRange(QCPRange)));
    // pass data points to graphs:
    plot->graph(0)->setData(x, y0);
    plot->graph(1)->setData(x, y1);
    // let the ranges scale themselves so graph 0 fits perfectly in the visible area:
    plot->graph(0)->rescaleAxes();
    // same thing for graph 1, but only enlarge ranges (in case graph 1 is smaller than graph 0):
    plot->graph(1)->rescaleAxes(true);
    // Note: we could have also just called customPlot->rescaleAxes(); instead
    // Allow user to drag axis ranges with mouse, zoom with mouse wheel and select graphs by clicking:
    plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);

 

标签:plot,graph,qcustomplot,ranges,绘图,y1,y0,QCPRange
From: https://www.cnblogs.com/kingkaixuan/p/17487280.html

相关文章

  • 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......
  • 实验六 turtle绘图与python库应用编程体验
    1fromturtleimport*234defmove(x,y):5penup()6goto(x,y)7pendown()8910defdraw(n,size=100):11foriinrange(n):12fd(size)13left(360/n)141516defmain():17pensize(2)18pen......
  • 实验6 turtle绘图与python库应用编程体验
    task1_11fromturtleimport*234defmove(x,y):5penup()6goto(x,y)7pendown()8910defdraw(n,size=100):11foriinrange(n):12fd(size)13left(360/n)141516defmain():17pensize(2)18......