当前位置:网站首页>Qcustomplot notes (I): qcustomplot adding data and curves
Qcustomplot notes (I): qcustomplot adding data and curves
2022-06-12 16:34:00 【I'm classmate Huang】
One . Preface
The landlord is studying recently QCustomplot Related content , So I want to record what I have learned , At the same time, it is also shared with those in need
The landlord is not involved in deep , It may not be right , No joy, no spray. . thank you
Two . The process
1. Drag one QWidget, Prompt for QCustomplot
2. Write code
// Data structure
QVector<double> x,y;
for(double xi=-2*M_PI;xi<2*M_PI;xi+=0.1)
{
x.push_back(xi);
y.push_back(sin(xi));
}
// Add curves , This sentence must be added , Otherwise, the curve will not be displayed
ui->widget->addGraph();
// Set up x Axis and y The name of the shaft
ui->widget->xAxis->setLabel(" This is a X Axis ");
ui->widget->yAxis->setLabel(" This is a Y Axis ");
// Set up the data
ui->widget->graph(0)->setData(x,y);
// Set curve name
ui->widget->graph(0)->setName("y=sin(x)");
// Set the display curve name
ui->widget->legend->setVisible(true);
// Set the font attribute of curve name
ui->widget->legend->setFont(QFont(" Microsoft YaHei ",13));
// Set adaption
ui->widget->rescaleAxes(true);

3. Add multiple groups of data , Adding multiple groups of data is the same as adding a single group of data , I think it's very convenient to add this ,QCustomplot The author of is really a great man
// Data structure
QVector<double> x,y;
for(double xi=-2*M_PI;xi<2*M_PI;xi+=0.1)
{
x.push_back(xi);
y.push_back(sin(xi));
}
// Add curves , This sentence must be added , Otherwise, the curve will not be displayed
ui->widget->addGraph();
// Set up x Axis and y The name of the shaft
ui->widget->xAxis->setLabel(" This is a X Axis ");
ui->widget->yAxis->setLabel(" This is a Y Axis ");
// Set up the data
ui->widget->graph(0)->setData(x,y);
// Set curve name
ui->widget->graph(0)->setName("y=sin(x)");
// Set the display curve name
ui->widget->legend->setVisible(true);
// Set the font attribute of curve name
ui->widget->legend->setFont(QFont(" Microsoft YaHei ",13));
// Set adaption
QVector<double> x1,y1;
for(double xx=-2*M_PI;xx<2*M_PI;xx+=0.1)
{
x1.push_back(xx);
y1.push_back(cos(xx));
}
//
QPen pen;
pen.setWidth(3);
pen.setColor(Qt::green);
ui->widget->addGraph();
// Set the curve color
ui->widget->graph(1)->setPen(pen);
ui->widget->graph(1)->setData(x1,y1);
ui->widget->graph(1)->setName("y=cos(x)");
ui->widget->rescaleAxes(true);
//
QPen pen3;
pen3.setWidth(3);
pen3.setColor(Qt::yellow);
ui->widget->addGraph();
QVector<double> x2,y2;
for(int i=0;i<10;i++)
{
x2.push_back(i);
y2.push_back(i);
}
ui->widget->graph(2)->setPen(pen3);
ui->widget->graph(2)->setData(x2,y2);
ui->widget->graph(2)->setName("y=x");
// When adding multiple groups of data , This sentence must be placed at the end , To realize the self adaptation of the coordinate axis
ui->widget->rescaleAxes(true);

边栏推荐
- js监听用户是否打开屏幕焦点
- generate pivot data 1
- The C programming language (version 2) notes / 8 UNIX system interface / 8.5 instance (implementation of fopen and Getc functions)
- Differences between SQL and NoSQL of mongodb series
- Cookies and sessions
- MySQL系列之分库分表学习笔记
- Acwing high precision multiplication
- The C Programming Language(第 2 版) 笔记 / 8 UNIX 系统接口 / 8.6 实例(目录列表)
- acwing 800. Target and of array elements
- Mongodb learning and sorting (basic command learning of users, databases, collections and documents)
猜你喜欢

Sum of acwing796 submatrix

Leetcode 2194. Cells within a range in Excel table (yes, solved)

acwing794 高精度除法

Gopher to rust hot eye grammar ranking

批量--04---移动构件

超详细干货!Docker+PXC+Haproxy搭建高可用强一致性的MySQL集群

【研究】英文论文阅读——英语poor的研究人员的福利

Servlet API

What's the matter with pbootcms' if judgment failure and direct display of labels?

Which colleges are particularly easy to enter?
随机推荐
JS écoute si l'utilisateur allume le focus de l'écran
Exception assertion of assertj
[BSP video tutorial] BSP video tutorial issue 17: single chip microcomputer bootloader topic, startup, jump configuration and various usage of debugging and downloading (2022-06-10)
acwing 802. Interval sum (discretization)
vim 从嫌弃到依赖(16)——宏
MySQL interview arrangement
The C Programming Language(第 2 版) 笔记 / 7 输入与输出 / 7.8 其它函数
Probation period and overtime compensation -- knowledge before and after entering the factory labor law
<山东大学项目实训>渲染引擎系统(六)
generate pivot data 1
<山东大学项目实训>渲染引擎系统(七)
The C programming language (version 2) notes / 8 UNIX system interface / 8.5 instance (implementation of fopen and Getc functions)
RTOS RT thread bare metal system and multi thread system
1.delete
JS monitors whether the user opens the screen focus
<山东大学项目实训>渲染引擎系统(五)
<山东大学项目实训>渲染引擎系统(八-完)
Interview: do you understand the packing and unpacking operations?
What's the matter with pbootcms' if judgment failure and direct display of labels?
Kill program errors in the cradle with spotbugs