数字格式和精度
我们可以通过void QCPAxis::setNumberFormat ( const QString & formatCode)
设置轴数字属性。formatCode是一个字符串,
- 第一个参数和QString::number()关于Format的规定一致:
- 第二个参数和第三个参数都是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 t;
std::generate_n(std::back_inserter(t),2000,[n=-1000.0]()mutable {return (n++)*0.004;});
std::vector 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(t.begin(),t.end()),QVector(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(t.begin(),t.end()),QVector(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);
}