




免费预览已结束,剩余83页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Plot Screenshots: Simple Demo/ add two new graphs and set their look:customPlot-addGraph();customPlot-graph(0)-setPen(QPen(Qt:blue); / line color blue for first graphcustomPlot-graph(0)-setBrush(QBrush(QColor(0, 0, 255, 20); / first graph will be filled with translucent bluecustomPlot-addGraph();customPlot-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 x(250), y0(250), y1(250);for (int i=0; ixAxis2-setVisible(true);customPlot-xAxis2-setTickLabels(false);customPlot-yAxis2-setVisible(true);customPlot-yAxis2-setTickLabels(false);/ make left and bottom axes always transfer their ranges to right and top axes:connect(customPlot-xAxis, SIGNAL(rangeChanged(QCPRange), customPlot-xAxis2, SLOT(setRange(QCPRange);connect(customPlot-yAxis, SIGNAL(rangeChanged(QCPRange), customPlot-yAxis2, SLOT(setRange(QCPRange);/ pass data points to graphs:customPlot-graph(0)-setData(x, y0);customPlot-graph(1)-setData(x, y1);/ let the ranges scale themselves so graph 0 fits perfectly in the visible area:customPlot-graph(0)-rescaleAxes();/ same thing for graph 1, but only enlarge ranges (in case graph 1 is smaller than graph 0):customPlot-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:customPlot-setInteractions(QCP:iRangeDrag | QCP:iRangeZoom | QCP:iSelectPlottables);Plot Screenshots: Sinc Scatter DemocustomPlot-legend-setVisible(true);customPlot-legend-setFont(QFont(Helvetica,9);/ set locale to english, so we get english decimal separator:customPlot-setLocale(QLocale(QLocale:English, QLocale:UnitedKingdom);/ add confidence band graphs:customPlot-addGraph();QPen pen;pen.setStyle(Qt:DotLine);pen.setWidth(1);pen.setColor(QColor(180,180,180);customPlot-graph(0)-setName(Confidence Band 68%);customPlot-graph(0)-setPen(pen);customPlot-graph(0)-setBrush(QBrush(QColor(255,50,30,20);customPlot-addGraph();customPlot-legend-removeItem(customPlot-legend-itemCount()-1); / dont show two confidence band graphs in legendcustomPlot-graph(1)-setPen(pen);customPlot-graph(0)-setChannelFillGraph(customPlot-graph(1);/ add theory curve graph:customPlot-addGraph();pen.setStyle(Qt:DashLine);pen.setWidth(2);pen.setColor(Qt:red);customPlot-graph(2)-setPen(pen);customPlot-graph(2)-setName(Theory Curve);/ add data point graph:customPlot-addGraph();customPlot-graph(3)-setPen(QPen(Qt:blue);customPlot-graph(3)-setLineStyle(QCPGraph:lsNone);customPlot-graph(3)-setScatterStyle(QCPScatterStyle(QCPScatterStyle:ssCross, 4);customPlot-graph(3)-setErrorType(QCPGraph:etValue);customPlot-graph(3)-setErrorPen(QPen(QColor(180,180,180);customPlot-graph(3)-setName(Measurement);/ generate ideal sinc curve data and some randomly perturbed data for scatter plot:QVector x0(250), y0(250);QVector yConfUpper(250), yConfLower(250);for (int i=0; i250; +i)x0i = (i/249.0-0.5)*30+0.01; / by adding a small offset we make sure not do divide by zero in next code liney0i = qSin(x0i)/x0i; / sinc functionyConfUpperi = y0i+0.15;yConfLoweri = y0i-0.15;x0i *= 1000;QVector x1(50), y1(50), y1err(50);for (int i=0; igraph(0)-setData(x0, yConfUpper);customPlot-graph(1)-setData(x0, yConfLower);customPlot-graph(2)-setData(x0, y0);customPlot-graph(3)-setDataValueError(x1, y1, y1err);customPlot-graph(2)-rescaleAxes();customPlot-graph(3)-rescaleAxes(true);/ setup look of bottom tick labels:customPlot-xAxis-setTickLabelRotation(30);customPlot-xAxis-setAutoTickCount(9);customPlot-xAxis-setNumberFormat(ebc);customPlot-xAxis-setNumberPrecision(1);customPlot-xAxis-moveRange(-10);/ make top right axes clones of bottom left axes. Looks prettier:customPlot-axisRect()-setupFullAxesBox();Plot Screenshots: Scatter Style DemocustomPlot-legend-setVisible(true);customPlot-legend-setFont(QFont(Helvetica, 9);customPlot-legend-setRowSpacing(-3);QVector shapes;shapes QCPScatterStyle:ssCross;shapes QCPScatterStyle:ssPlus;shapes QCPScatterStyle:ssCircle;shapes QCPScatterStyle:ssDisc;shapes QCPScatterStyle:ssSquare;shapes QCPScatterStyle:ssDiamond;shapes QCPScatterStyle:ssStar;shapes QCPScatterStyle:ssTriangle;shapes QCPScatterStyle:ssTriangleInverted;shapes QCPScatterStyle:ssCrossSquare;shapes QCPScatterStyle:ssPlusSquare;shapes QCPScatterStyle:ssCrossCircle;shapes QCPScatterStyle:ssPlusCircle;shapes QCPScatterStyle:ssPeace;shapes QCPScatterStyle:ssCustom;QPen pen;/ add graphs with different scatter styles:for (int i=0; iaddGraph();pen.setColor(QColor(qSin(i*0.3)*100+100, qSin(i*0.6+0.7)*100+100, qSin(i*0.4+0.6)*100+100);/ generate data:QVector x(10), y(10);for (int k=0; kgraph()-setData(x, y);customPlot-graph()-rescaleAxes(true);customPlot-graph()-setPen(pen);customPlot-graph()-setName(QCPScatterStyle:staticMetaObject.enumerator(QCPScatterStyle:staticMetaObject.indexOfEnumerator(ScatterShape).valueToKey(shapes.at(i);customPlot-graph()-setLineStyle(QCPGraph:lsLine);/ set scatter style:if (shapes.at(i) != QCPScatterStyle:ssCustom)customPlot-graph()-setScatterStyle(QCPScatterStyle(shapes.at(i), 10);elseQPainterPath customScatterPath;for (int i=0; igraph()-setScatterStyle(QCPScatterStyle(customScatterPath, QPen(Qt:black, 0), QColor(40, 70, 255, 50), 10);/ set blank axis lines:customPlot-rescaleAxes();customPlot-xAxis-setTicks(false);customPlot-yAxis-setTicks(false);customPlot-xAxis-setTickLabels(false);customPlot-yAxis-setTickLabels(false);/ make top right axes clones of bottom left axes:customPlot-axisRect()-setupFullAxesBox();Plot Screenshots: Styled Plot Demo/ prepare data:QVector x1(20), y1(20);QVector x2(100), y2(100);QVector x3(20), y3(20);QVector x4(20), y4(20);for (int i=0; ix1.size(); +i)x1i = i/(double)x1.size()*10;y1i = qCos(x1i*0.8+qSin(x1i*0.16+1.0)*qSin(x1i*0.54)+1.4;for (int i=0; ix2.size(); +i)x2i = i/(double)x2.size()*10;y2i = qCos(x2i*0.85+qSin(x2i*0.165+1.1)*qSin(x2i*0.50)+1.7;for (int i=0; ix3.size(); +i)x3i = i/(double)x3.size()*10;y3i = 0.05+3*(0.5+qCos(x3i*x3i*0.2+2)*0.5)/(double)(x3i+0.7)+qrand()/(double)RAND_MAX*0.01;for (int i=0; iaddGraph();graph1-setData(x1, y1);graph1-setScatterStyle(QCPScatterStyle(QCPScatterStyle:ssCircle, QPen(Qt:black, 1.5), QBrush(Qt:white), 9);graph1-setPen(QPen(QColor(120, 120, 120), 2);QCPGraph *graph2 = customPlot-addGraph();graph2-setData(x2, y2);graph2-setPen(Qt:NoPen);graph2-setBrush(QColor(200, 200, 200, 20);graph2-setChannelFillGraph(graph1);QCPBars *bars1 = new QCPBars(customPlot-xAxis, customPlot-yAxis);customPlot-addPlottable(bars1);bars1-setWidth(9/(double)x3.size();bars1-setData(x3, y3);bars1-setPen(Qt:NoPen);bars1-setBrush(QColor(10, 140, 70, 160);QCPBars *bars2 = new QCPBars(customPlot-xAxis, customPlot-yAxis);customPlot-addPlottable(bars2);bars2-setWidth(9/(double)x4.size();bars2-setData(x4, y4);bars2-setPen(Qt:NoPen);bars2-setBrush(QColor(10, 100, 50, 70);bars2-moveAbove(bars1);/ move bars above graphs and grid below bars:customPlot-addLayer(abovemain, customPlot-layer(main), QCustomPlot:limAbove);customPlot-addLayer(belowmain, customPlot-layer(main), QCustomPlot:limBelow);graph1-setLayer(abovemain);customPlot-xAxis-grid()-setLayer(belowmain);customPlot-yAxis-grid()-setLayer(belowmain);/ set some pens, brushes and backgrounds:customPlot-xAxis-setBasePen(QPen(Qt:white, 1);customPlot-yAxis-setBasePen(QPen(Qt:white, 1);customPlot-xAxis-setTickPen(QPen(Qt:white, 1);customPlot-yAxis-setTickPen(QPen(Qt:white, 1);customPlot-xAxis-setSubTickPen(QPen(Qt:white, 1);customPlot-yAxis-setSubTickPen(QPen(Qt:white, 1);customPlot-xAxis-setTickLabelColor(Qt:white);customPlot-yAxis-setTickLabelColor(Qt:white);customPlot-xAxis-grid()-setPen(QPen(QColor(140, 140, 140), 1, Qt:DotLine);customPlot-yAxis-grid()-setPen(QPen(QColor(140, 140, 140), 1, Qt:DotLine);customPlot-xAxis-grid()-setSubGridPen(QPen(QColor(80, 80, 80), 1, Qt:DotLine);customPlot-yAxis-grid()-setSubGridPen(QPen(QColor(80, 80, 80), 1, Qt:DotLine);customPlot-xAxis-grid()-setSubGridVisible(true);customPlot-yAxis-grid()-setSubGridVisible(true);customPlot-xAxis-grid()-setZeroLinePen(Qt:NoPen);customPlot-yAxis-grid()-setZeroLinePen(Qt:NoPen);customPlot-xAxis-setUpperEnding(QCPLineEnding:esSpikeArrow);customPlot-yAxis-setUpperEnding(QCPLineEnding:esSpikeArrow);QLinearGradient plotGradient;plotGradient.setStart(0, 0);plotGradient.setFinalStop(0, 350);plotGradient.setColorAt(0, QColor(80, 80, 80);plotGradient.setColorAt(1, QColor(50, 50, 50);customPlot-setBackground(plotGradient);QLinearGradient axisRectGradient;axisRectGradient.setStart(0, 0);axisRectGradient.setFinalStop(0, 350);axisRectGradient.setColorAt(0, QColor(80, 80, 80);axisRectGradient.setColorAt(1, QColor(30, 30, 30);customPlot-axisRect()-setBackground(axisRectGradient);customPlot-rescaleAxes();customPlot-yAxis-setRange(0, 2);Plot Screenshots: Color Map Demo/ configure axis rect:customPlot-setInteractions(QCP:iRangeDrag|QCP:iRangeZoom); / this will also allow rescaling the color scale by dragging/zoomingcustomPlot-axisRect()-setupFullAxesBox(true);customPlot-xAxis-setLabel(x);customPlot-yAxis-setLabel(y);/ set up the QCPColorMap:QCPColorMap *colorMap = new QCPColorMap(customPlot-xAxis, customPlot-yAxis);customPlot-addPlottable(colorMap);int nx = 200;int ny = 200;colorMap-data()-setSize(nx, ny); / we want the color map to have nx * ny data pointscolorMap-data()-setRange(QCPRange(-4, 4), QCPRange(-4, 4); / and span the coordinate range -4.4 in both key (x) and value (y) dimensions/ now we assign some data, by accessing the QCPColorMapData instance of the color map:double x, y, z;for (int xIndex=0; xIndexnx; +xIndex)for (int yIndex=0; yIndexdata()-cellToCoord(xIndex, yIndex, &x, &y);double r = 3*qSqrt(x*x+y*y)+1e-2;z = 2*x*(qCos(r+2)/r-qSin(r+2)/r); / the B field strength of dipole radiation (modulo physical constants)colorMap-data()-setCell(xIndex, yIndex, z);/ add a color scale:QCPColorScale *colorScale = new QCPColorScale(customPlot);customPlot-plotLayout()-addElement(0, 1, colorScale); / add it to the right of the main axis rectcolorScale-setType(QCPAxis:atRight); / scale shall be vertical bar with tick/axis labels right (actually atRight is already the default)colorMap-setColorScale(colorScale); / associate the color map with the color scalecolorScale-axis()-setLabel(Magnetic Field Strength);/ set the color gradient of the color map to one of the presets:colorMap-setGradient(QCPColorGradient:gpPolar);/ we could have also created a QCPColorGradient instance and added own colors to/ the gradient, see the documentation of QCPColorGradient for whats possible./ rescale the data dimension (color) such that all data points lie in the span visualized by the color gradient:colorMap-rescaleDataRange();/ make sure the axis rect and color scale synchronize their bottom and top margins (so they line up):QCPMarginGroup *marginGroup = new QCPMarginGroup(customPlot);customPlot-axisRect()-setMarginGroup(QCP:msBottom|QCP:msTop, marginGroup);colorScale-setMarginGroup(QCP:msBottom|QCP:msTop, marginGroup);/ rescale the key (x) and value (y) axes so the whole color map is visible:customPlot-rescaleAxes();Plot Screenshots: Scatter Pixmap DemocustomPlot-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 Photovoltaicnenergy barometer 2011);/ set data:QVector year, value;year 2005 2006 2007 2008 2009 2010;value 2.17 3.42 4.94 10.38 15.86 graph()-setData(year, value);/ set title of plot:customPlot-plotLayout()-insertRow(0);customPlot-plotLayout()-addElement(0, 0, new QCPPlotTitle(customPlot, Regenerative Energies);/ set a fixed tick-step to one tick per year value:customPlot-xAxis-setAutoTickStep(false);customPlot-xAxis-setTickStep(1);customPlot-xAxis-setSubTickCount(3);/ other axis configurations:customPlot-xAxis-setLabel(Year);customPlot-yAxis-setLabel(Installed Gigawatts ofnphotovoltaic 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-setSubTickCount(0);customPlot-yAxis2-setSubTickCount(0);customPlot-xAxis-setRange(2004.5, 2010.5);customPlot-yAxis-setRange(0, 30);/ setup legend:customPlot-legend-setFont(QFont(font().family(), 7);customPlot-legend-setIconSize(50, 20);customPlot-legend-setVisible(true);Plot Screenshots: Realtime Data DemoSetup function:customPlot-addGraph(); / blue linecustomPlot-graph(0)-setPen(QPen(Qt:blue);customPlot-graph(0)-setBrush(QBrush(QColor(240, 255, 200);customPlot-graph(0)-setAntialiasedFill(false);customPlot-addGraph(); / red linecustomPlot-graph(1)-setPen(QPen(Qt:red);customPlot-graph(0)-setChannelFillGraph(customPlot-graph(1);customPlot-addGraph(); / blue dotcustomPlot-graph(2)-setPen(QPen(Qt:blue);customPlot-graph(2)-setLineStyle(QCPGraph:lsNone);customPlot-graph(2)-setScatterStyle(QCPScatterStyle:ssDisc);customPlot-addGraph(); / red dotcustomPlot-graph(3)-setPen(QPen(Qt:red);customPlot-graph(3)-setLineStyle(QCPGraph:lsNone);customPlot-graph(3)-setScatterStyle(QCPScatterStyle:ssDisc);customPlot-xAxis-setTickLabelType(QCPAxis:ltDateTime);customPlot-xAxis-setDateTimeFormat(hh:mm:ss);customPlot-xAxis-setAutoTickStep(false);customPlot-xAxis-setTickStep(2);customPlot-axisRect()-setupFullAxesBox();/ make left and bottom axes transfer their ranges to right and top axes:connect(customPlot-xAxis, SIGNAL(rangeChanged(QCPRange), customPlot-xAxis2, SLOT(setRange(QCPRange);connect(customPlot-yAxis, SIGNAL(rangeChanged(QCPRange), customPlot-yAxis2, SLOT(setRange(QCPRange);/ setup a timer that repeatedly calls MainWindow:realtimeDataSlot:connect(&dataTimer, SIGNAL(timeout(), this, SLOT(realtimeDataSlot();dataTimer.start(0); / Interval 0 means to refresh as fast as possiblerealtimeDataSlot, called by timer:/ calculate two new data points:double key = QDateTime:currentDateTime().toMSecsSinceEpoch()/1000.0;static double lastPointKey = 0;if (key-lastPointKey 0.01) / at most add point every 10 msdouble value0 = qSin(key); /qSin(key*1.6+qCos(key*1.7)*2)*10 + qSin(key*1.2+0.56)*20 + 26;double value1 = qCos(key); /qSin(key*1.3+qCos(key*1.2)*1.2)*7 + qSin(key*0.9+0.26)*24 + 26;/ add data to lines:ui-customPlot-graph(0)-addData(key, value0);ui-customPlot-graph(1)-addData(key, value1);/ set data of dots:ui-customPlot-graph(2)-clearData();ui-customPlot-graph(2)-addData(key, value0);ui-customPlot-graph(3)-clearData();ui-customPlot-graph(3)-addData(key, value1);/ remove data
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 南京安全c证题库练习及答案解析
- 三联交通安全员考试题库及答案解析
- 2025江苏安全员c2证考试题库及答案解析
- 水电设计维护方案范本
- 基础护理1000题题库及答案解析
- 安全员c证考试题库答卷及答案解析
- 期货从业资格格考试刷课及答案解析
- 钢瓶安全测试题解析及答案解析
- 年终工作总结报表
- 员工半年工作总结
- 2025-2030年中国核子及核辐射测量仪器行业竞争格局及发展趋势分析报告
- 2024年4月全国自考00054管理学原理真题
- 银行保险机构安全保卫工作自查操作手册
- 2025-2030中国咖喱粉市场消费调查及投资效益趋势预测研究报告
- 餐饮食堂“十统一六到位”管理培训
- 工业生产许可证实施细则
- 增加子女抚养费协议书
- 中学宿舍卫生管理制度
- 少吃糖预防蛀牙
- 《实验设计与数据分析》课件
- 大学安全纪律教育主题班会
评论
0/150
提交评论