QCustomplot (四) 控制轴相关属性
2023-09-27 14:27:31 时间
数字格式和精度
我们可以通过void QCPAxis::setNumberFormat ( const QString & formatCode)
设置轴数字属性。formatCode是一个字符串,
- 第一个参数和QString::number()关于Format的规定一致:
Format | Meaning |
---|---|
e | format as [-]9.9e[+ |
E | format as [-]9.9E[+ |
f | format as [-]9.9 |
g | use e or f format, whichever is the most concise |
G | use E or f format, whichever is the most concise |
- 第二个参数和第三个参数都是QCustomPlot的参数,它们是可选的。
其中第二个参数是为了让第一个参数的科学计数法更加beatiful的,用b表示。乘法默认情况下是使用居中的dot表示,如果你想要用 × \times ×表示,那么你可以用字符c(cross)表示。
轴颜色
通过QPen来设置
标签
- 字体 setLabelFonts
刻度
- setTickLabelColor 刻度颜色
- setTickLabelRotation 倾斜度
- setTickLength 主刻度长度
- setSubTicks 次刻度
- setSubTickLength 次刻度长度
范围
customPlot->xAxis->setRange().
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
QChart q;
this->resize(800,500);
QCustomPlot *customPlot=new QCustomPlot();
customPlot->setParent(this);
//customPlot->resize(650,500);
QHBoxLayout * pLayout=new QHBoxLayout;
pLayout->addWidget(customPlot);
this->setLayout(pLayout);
// generate some data:
std::vector<double> t;
std::generate_n(std::back_inserter(t),2000,[n=-1000.0]()mutable {return (n++)*0.004;});
std::vector<double> y1,y2;
std::transform(t.begin(),t.end(),std::back_inserter(y1),[](double ele){return sin(ele);});
std::transform(t.begin(),t.end(),std::back_inserter(y2),[](double ele){return cos(ele);});
QPen pen;
pen.setStyle(Qt::DotLine);
customPlot->addGraph();
customPlot->graph(0)->setName("y=sin(x)");
customPlot->graph(0)->setPen(QPen(Qt::red));
customPlot->graph(0)->setData(QVector<double>(t.begin(),t.end()),QVector<double>(y1.begin(),y1.end()));
customPlot->addGraph();
customPlot->graph(1)->setPen(QPen(Qt::blue));
customPlot->graph(1)->setName("y=cos(x)");
customPlot->graph(1)->setData(QVector<double>(t.begin(),t.end()),QVector<double>(y2.begin(),y2.end()));
customPlot->graph(0)->setBrush(QBrush(QColor(255,50,30,20)));
customPlot->graph(0)->setChannelFillGraph(customPlot->graph(1));
customPlot->legend->removeItem(customPlot->legend->itemCount()-1); // don't show two confidence band graphs in legend
// give the axes some labels:
customPlot->xAxis->setLabel("x");
customPlot->xAxis->setSubTicks(true);
customPlot->xAxis->setTickLength(50);
customPlot->xAxis->setSubTickLength(30);
customPlot->xAxis->setTickLabelColor(Qt::darkGray);
customPlot->xAxis->setTickLabelRotation(30);
customPlot->xAxis->setNumberFormat("eb");
customPlot->yAxis->setNumberPrecision(1);
customPlot->yAxis->setLabel("y");
// set axes ranges, so we see all data:
customPlot->xAxis->setRange(-3.14/2, 3.14);
customPlot->yAxis->setRange(0, 1);
customPlot->legend->setVisible(true);
}
相关文章
- 【控制】MPC
- DACL原理.控制文件的访问权限(文件,注册表.目录.等任何带有安全属性的对象.)
- Javascript语法去控制Web控件的Enabled属性
- java 的访问权限控制
- Shiro权限控制框架
- Spring学习3—控制反转(IOC)Spring依赖注入(DI)和控制反转(IOC)
- 表格里面控制分页的方法使用
- 远程控制电脑工具
- 关于MySQL的权限控制
- spring成神之路第二十篇:@Conditional 通过条件来控制 bean 的注册
- 【HTML】HTML 表单 ③ ( label 标签 | 增大表单触发面积 | label 标签包含表单 | 通过 label 标签的 for 属性控制触发表单 )
- Struts2中基于Annotation的细粒度权限控制
- 小程序自定义Tabbar控制Tabbar的数量
- SPI模式下MCU对SD卡的控制及操作命令(转)
- 《LED调光-DMX512灯光协义接收控制》转
- Retrofit2实现缓存、离线缓存、在线缓存及@headers控制缓存时间
- C控制语句:分支和跳转1