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

qcustomplot 绘图 4

时间:2023-06-17 12:33:56浏览次数:27  
标签:false customPlot graph yAxis2 qcustomplot pen 绘图 legend

关注点:

设置背景、增加文字图层、第二坐标显示控制、设置label显示位置

    auto customPlot  = plot;
    customPlot->axisRect()->setBackground(QPixmap("./solarpanels.jpg"));
    customPlot->addGraph();
    customPlot->graph()->setLineStyle(QCPGraph::lsLine);
    QPen pen;
    pen.setColor(QColor(255, 200, 20, 200));
    pen.setStyle(Qt::DashLine);
    pen.setWidthF(2.5);
    customPlot->graph()->setPen(pen);
    customPlot->graph()->setBrush(QBrush(QColor(255,200,20,70)));
    customPlot->graph()->setScatterStyle(QCPScatterStyle(QPixmap("./sun.png")));
    // set graph name, will show up in legend next to icon:
    customPlot->graph()->setName("Data from Photovoltaic\nenergy barometer 2011");
    // set data:
    QVector<double> year, value;
    year  << 2005 << 2006 << 2007 << 2008  << 2009  << 2010 << 2011;
    value << 2.17 << 3.42 << 4.94 << 10.38 << 15.86 << 29.33 << 52.1;
    customPlot->graph()->setData(year, value);

    // set title of plot:
    customPlot->plotLayout()->insertRow(0);
    customPlot->plotLayout()->addElement(0, 0, new QCPTextElement(customPlot, "Regenerative Energies", QFont("sans", 12, QFont::Bold)));
    // axis configurations:
    customPlot->xAxis->setLabel("Year");
    customPlot->yAxis->setLabel("Installed Gigawatts of\nphotovoltaic in the European Union");
//    customPlot->xAxis2->setVisible(true);
//    customPlot->yAxis2->setVisible(true);
//    customPlot->xAxis2->setTickLabels(false);
//    customPlot->yAxis2->setTickLabels(false);
//    customPlot->xAxis2->setTicks(false);
//    customPlot->yAxis2->setTicks(false);
//    customPlot->xAxis2->setSubTicks(false);
//    customPlot->yAxis2->setSubTicks(false);
    customPlot->xAxis->setRange(2004.5, 2011.5);
    customPlot->yAxis->setRange(0, 52);
    // setup legend:
    customPlot->legend->setFont(QFont(font().family(), 7));
    customPlot->legend->setIconSize(50, 20);
    customPlot->legend->setVisible(true);
    customPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignLeft | Qt::AlignTop);

 

标签:false,customPlot,graph,yAxis2,qcustomplot,pen,绘图,legend
From: https://www.cnblogs.com/kingkaixuan/p/17487343.html

相关文章

  • qcustomplot 绘图 3
    内容:包络线(填充),散点图,线型,errorBar等不同坐标的显示技巧:1、设置不同的x轴,2、QCPErrorBars特有的setDataPlottable(...);plot->legend->setVisible(true);plot->legend->setFont(QFont("Helvetica",9));//setlocaletoenglish,sowegetenglishdecimals......
  •  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):......