Qt第三方QCustomPlot的使用---kalrry
一、参考博客
- QCustomPlot中图例的相关设置
- QCustomPlot使用手册
- QCustomPlot中图例的相关设置
- QCustomPlot更改图例legend位置
- QCustomPlot设定图例的位置
- QCustomPlot
End、例子
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));
}
m_Multichannel = new QCustomPlot();
m_Multichannel = ui->myCustomPlot1;
m_Multichannel->addGraph();
======================QCustomPlot设置【下】============================================================
m_Multichannel->xAxis->setLabel("这是X轴");
m_Multichannel->yAxis->setLabel("这是Y轴");
======================设置坐标轴========================================================================================
m_Multichannel->xAxis->setVisible(true);
m_Multichannel->yAxis->setVisible(true);
======================手动设置坐标轴的范围==================================================================
======================改变刻度起始原点========================================================================================
======================设置刻度数量========================================================================================
======================设置坐标轴线条颜色属性==================================================================
m_Multichannel->xAxis->setBasePen(QPen(Qt::white,1,Qt::PenStyle::SolidLine));
m_Multichannel->yAxis->setBasePen(QPen(Qt::white,1,Qt::PenStyle::SolidLine));
======================设置背景网格线是否显示--默认显示==================================================================
======================设置背景色========================================================================================
m_Multichannel->setBackground(QColor(25,35,45));
======================设置背景/网格线条颜色属性==================================================================
m_Multichannel->xAxis->grid()->setSubGridPen(QPen(QColor(50, 50, 50), 1, Qt::DotLine));
m_Multichannel->yAxis->grid()->setSubGridPen(QPen(QColor(50, 50, 50), 1, Qt::DotLine));
m_Multichannel->xAxis->grid()->setSubGridVisible(true);
m_Multichannel->yAxis->grid()->setSubGridVisible(true);
m_Multichannel->xAxis->grid()->setZeroLinePen(QPen(QColor(180, 180, 180)));
m_Multichannel->yAxis->grid()->setZeroLinePen(QPen(QColor(180, 180, 180)));
======================刻度线长度和颜色==================================================================
m_Multichannel->xAxis->setTickPen(QPen(QColor(255, 255, 255)));
m_Multichannel->xAxis->setTickLengthOut(5);
m_Multichannel->yAxis->setTickPen(QPen(QColor(255, 255, 255)));
m_Multichannel->yAxis->setTickLengthOut(5);
m_Multichannel->xAxis->setSubTickPen(QPen(QColor(255, 255, 255)));
m_Multichannel->xAxis->setSubTickLengthOut(0.5);
m_Multichannel->yAxis->setSubTickPen(QPen(QColor(255, 255, 255)));
m_Multichannel->yAxis->setSubTickLengthOut(0.5);
======================坐标轴结束显示箭头==================================================================
m_Multichannel->xAxis->setUpperEnding(QCPLineEnding::esSpikeArrow);
m_Multichannel->yAxis->setUpperEnding(QCPLineEnding::esSpikeArrow);
m_Multichannel->xAxis->setLabelColor(QColor(255, 255, 255));
m_Multichannel->xAxis->setTickLabelColor(QColor(255, 255, 255));
m_Multichannel->yAxis->setLabelColor(QColor(255, 255, 255));
m_Multichannel->yAxis->setTickLabelColor(QColor(255, 255, 255));
======================QCustomPlot设置【上】图示教程地址:https://cloud.tencent.com/developer/article/2150466===================================================================
======================设置曲线颜色QPen pen3;==================================================================
QPen pen0;
pen0.setWidth(1);
pen0.setColor(Qt::green);
m_Multichannel->graph(0)->setPen(pen0);
m_Multichannel->graph(0)->setData(x,y);
m_Multichannel->graph(0)->setName("y=sin(x)");
m_Multichannel->legend->setVisible(true);
m_Multichannel->legend->setFont(QFont("微软雅黑",13));
m_Multichannel->rescaleAxes(true);
======================Qt QCustomPlot设置x轴、y轴刻度以及轴、文字颜色============================================
QFont font;
font.setPixelSize(14);
m_pPlotWidget->xAxis->setLabelFont(font);
m_pPlotWidget->yAxis->setLabelFont(font);
font.setPixelSize(14);
m_pPlotWidget->xAxis->setTickLabelFont(font);
m_pPlotWidget->yAxis->setTickLabelFont(font);
m_pPlotWidget->xAxis->setLabelColor(QColor(255, 0, 0));
m_pPlotWidget->xAxis->setTickLabelColor(QColor(255, 0, 0));
m_pPlotWidget->yAxis->setLabelColor(QColor(255, 0, 0));
m_pPlotWidget->yAxis->setTickLabelColor(QColor(255, 0, 0));
QPen pen = m_pPlotWidget->xAxis->basePen();
pen.setColor(QColor(255, 0, 0));
m_pPlotWidget->xAxis->setTickPen(pen);
m_pPlotWidget->xAxis->setBasePen(pen);
m_pPlotWidget->xAxis->setSubTickPen(pen);
pen = m_pPlotWidget->yAxis->basePen();
pen.setColor(QColor(255, 0, 0));
m_pPlotWidget->yAxis->setTickPen(pen);
m_pPlotWidget->yAxis->setBasePen(pen);
m_pPlotWidget->yAxis->setSubTickPen(pen);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)