本文整理汇总了C++中QCustomPlot::addGraph方法的典型用法代码示例。如果您正苦于以下问题:C++ QCustomPlot::addGraph方法的具体用法?C++ QCustomPlot::addGraph怎么用?C++ QCustomPlot::addGraph使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QCustomPlot
的用法示例。
在下文中一共展示了QCustomPlot::addGraph方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: completeGraph
// Once channel details are known, complete the graph with details that depend upon the channel.
void LteRlcGraphDialog::completeGraph(bool may_be_empty)
{
QCustomPlot *rp = ui->rlcPlot;
// If no channel chosen already, try to use currently selected frame.
findChannel(may_be_empty);
// Set window title here.
if (graph_.channelSet) {
QString dlg_title = tr("LTE RLC Graph (UE=%1 chan=%2%3 %4 - %5)")
.arg(graph_.ueid)
.arg((graph_.channelType == CHANNEL_TYPE_SRB) ? "SRB" : "DRB")
.arg(graph_.channelId)
.arg((graph_.direction == DIRECTION_UPLINK) ? "UL" : "DL")
.arg((graph_.rlcMode == RLC_UM_MODE) ? "UM" : "AM");
setWindowTitle(dlg_title);
}
else {
setWindowTitle(tr("LTE RLC Graph - no channel selected"));
}
// Set colours/styles for each of the traces on the graph.
QCustomPlot *sp = ui->rlcPlot;
base_graph_ = sp->addGraph(); // All: Selectable segments
base_graph_->setPen(QPen(QBrush(Qt::black), 0.25));
reseg_graph_ = sp->addGraph();
reseg_graph_->setPen(QPen(QBrush(Qt::lightGray), 0.25));
acks_graph_ = sp->addGraph();
acks_graph_->setPen(QPen(QBrush(graph_color_ack), 1.0));
nacks_graph_ = sp->addGraph();
nacks_graph_->setPen(QPen(QBrush(graph_color_nack), 0.25));
// Create tracer
tracer_ = new QCPItemTracer(sp);
sp->addItem(tracer_);
tracer_->setVisible(false);
toggleTracerStyle(true);
// Change label on save/export button.
QPushButton *save_bt = ui->buttonBox->button(QDialogButtonBox::Save);
save_bt->setText(tr("Save As" UTF8_HORIZONTAL_ELLIPSIS));
connect(rp, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(graphClicked(QMouseEvent*)));
connect(rp, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(mouseMoved(QMouseEvent*)));
connect(rp, SIGNAL(mouseRelease(QMouseEvent*)), this, SLOT(mouseReleased(QMouseEvent*)));
disconnect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
this->setResult(QDialog::Accepted);
// Extract the data that the graph can use.
fillGraph();
}
示例2: initPlotter
void MainWindow::initPlotter()
{
QCustomPlot *cp = this->ui->plotter;
cp->addGraph();
cp->addGraph();
cp->addGraph();
cp->xAxis->setLabel("Epoch");
cp->yAxis->setLabel("fitness");
cp->graph(0)->setPen(QPen(Qt::blue));
cp->graph(1)->setPen(QPen(Qt::red));
cp->graph(2)->setPen(QPen(Qt::green));
cp->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
cp->setLocale(QLocale(QLocale::Portuguese, QLocale::Brazil));
cp->legend->setVisible(true);
}
示例3: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMainWindow window;
// setup customPlot as central widget of window:
QCustomPlot customPlot;
window.setCentralWidget(&customPlot);
// create plot (from quadratic plot example):
QVector<double> x(101), y(101);
for (int i=0; i<101; ++i)
{
x[i] = i/50.0 - 1;
y[i] = x[i]*x[i];
}
customPlot.addGraph();
customPlot.graph(0)->setData(x, y);
customPlot.xAxis->setLabel(QLatin1String("x"));
customPlot.yAxis->setLabel(QLatin1String("y"));
customPlot.rescaleAxes();
window.setGeometry(100, 100, 500, 400);
window.show();
return a.exec();
}
示例4: QWidget
MissionElevationDisplay::MissionElevationDisplay(QWidget *parent) :
QWidget(parent),
ui(new Ui::MissionElevationDisplay),
m_uasInterface(NULL),
m_uasWaypointMgr(NULL),
m_totalDistance(0),
m_elevationData(NULL),
m_useHomeAltOffset(false),
m_homeAltOffset(0.0),
m_elevationShown(false)
{
ui->setupUi(this);
ui->sampleSpinBox->setEnabled(false);
QCustomPlot* customPlot = ui->customPlot;
customPlot->addGraph(); // Mission Elevation Graph (ElevationGraphMissionId)
customPlot->graph(ElevationGraphMissionId)->setPen(QPen(Qt::blue)); // line color blue for mission data
customPlot->graph(ElevationGraphMissionId)->setBrush(QBrush(QColor(0, 0, 255, 20))); // first graph will be filled with translucent blue
customPlot->addGraph(); // Google Elevation Graph (ElevationGraphElevationId)
customPlot->graph(ElevationGraphElevationId)->setPen(QPen(Qt::red)); // line color red for elevation data
customPlot->graph(ElevationGraphElevationId)->setBrush(QBrush(QColor(255, 0, 0, 20))); // first graph will be filled with translucent blue
customPlot->graph(ElevationGraphElevationId)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDiamond, 10));
customPlot->xAxis->setLabel("distance (m)");
customPlot->yAxis->setLabel("altitude (m)");
// set default ranges for Alt and distance
customPlot->xAxis->setRange(0,ElevationDefaultDistanceMax); //m
customPlot->yAxis->setRange(ElevationDefaultAltMin,ElevationDefaultAltMax); //m
QFont legendFont = font();
legendFont.setPointSize(9);
customPlot->legend->setFont(legendFont);
// set a more compact font size for bottom and left axis tick labels:
customPlot->xAxis->setTickLabelFont(QFont(QFont().family(), 9));
customPlot->xAxis->setLabelFont(QFont(QFont().family(), 9));
customPlot->yAxis->setTickLabelFont(QFont(QFont().family(), 9));
customPlot->yAxis->setLabelFont(QFont(QFont().family(), 9));
customPlot->replot();
connect(UASManager::instance(),SIGNAL(activeUASSet(UASInterface*)),this,SLOT(activeUASSet(UASInterface*)));
activeUASSet(UASManager::instance()->getActiveUAS());
connect(ui->infoButton, SIGNAL(clicked()), this, SLOT(showInfoBox()));
}
示例5: QDialog
CompassMotorCalibrationDialog::CompassMotorCalibrationDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::CompassMotorCalibrationDialog),
m_uasInterface(NULL)
{
ui->setupUi(this);
QCustomPlot* customPlot = ui->customPlot;
customPlot->addGraph();
customPlot->graph(GRAPH_ID_INTERFERENCE)->setPen(QPen(GRAPH_COLOR_INTERFERENCE)); // line color blue for first graph
customPlot->graph(GRAPH_ID_INTERFERENCE)->setBrush(QBrush(GRAPH_COLOR_INTERFERENCE_FILL)); // first graph will be filled with translucent blue
customPlot->xAxis->setLabel("Throttle (%)");
customPlot->yAxis->setLabel("Interference (%)");
customPlot->yAxis->setLabelColor(GRAPH_COLOR_INTERFERENCE);
customPlot->xAxis->setRange(0,100);
customPlot->yAxis->setRange(0,100);
customPlot->addGraph();
customPlot->graph(GRAPH_ID_CURRENT)->setPen(QPen(GRAPH_COLOR_CURRENT)); // line color red for second graph
customPlot->graph(GRAPH_ID_CURRENT)->setBrush(QBrush(GRAPH_COLOR_CURRENT_FILL));
customPlot->yAxis2->setVisible(true);
customPlot->yAxis2->setLabel("Amps (A)");
customPlot->yAxis2->setLabelColor(GRAPH_COLOR_CURRENT);
customPlot->xAxis2->setRange(0,100);
customPlot->yAxis2->setRange(0,50);
customPlot->replot();
connect(ui->okButton, SIGNAL(clicked()), this, SLOT(okButtonClicked()));
connect(this, SIGNAL(about), this, SLOT(rejected()));
connect(UASManager::instance(),SIGNAL(activeUASSet(UASInterface*)),this,SLOT(activeUASSet(UASInterface*)));
activeUASSet(UASManager::instance()->getActiveUAS());
int ok = QMessageBox::warning(this, "Compass Motor Calibration", tr("CAUTION: Starting the compass motor calibration arms the motors.\n"
"Please make sure you have read and followed all instructions"
"before untertaking the calibration as serious injury could occur!"),
QMessageBox::Ok, QMessageBox::Cancel);
if (ok == QMessageBox::Cancel){
QTimer::singleShot(100, this, SLOT(cancelCalibration()));
}
}
示例6: update
bool TimeseriesGraph::update(const GRT::VectorDouble &sample ){
if( !initialized ) return false;
//Add the new sample to the buffer
data.push_back( sample );
//If the plot is hidden then there is no point in updating the graph
if( this->isHidden() ){
if( !lockRanges ){
//Reset the min and max values
minRange = 99e+99;
maxRange = -minRange;
}
return true;
}
QCustomPlot *plot = ui->graph;
//Clear any previous graphs
plot->clearGraphs();
//Get the data to plot
QVector<double> x( graphWidth );
vector< QVector<double> > y(numDimensions, QVector<double>(graphWidth) );
for (unsigned int i=0; i<graphWidth; i++)
{
x[i] = i;
for(unsigned int j=0; j<numDimensions; j++){
y[j][i] = data[i][j];
if( !lockRanges ){
if( data[i][j] < minRange ) minRange = data[i][j];
else if( data[i][j] > maxRange ) maxRange = data[i][j];
}
}
}
//Create the graphs
for(unsigned int j=0; j<numDimensions; j++){
plot->addGraph();
plot->graph(j)->setPen( QPen( colors[j%colors.size()] ));
plot->graph(j)->setData(x, y[j]);
}
// give the axes some labels:
plot->xAxis->setLabel("Time");
plot->yAxis->setLabel("Values");
// set axes ranges, so we see all data:
plot->xAxis->setRange(0, graphWidth);
plot->yAxis->setRange(minRange, maxRange);
plot->replot();
return true;
}
示例7: prepareChart
/** Makes pre-configuration of the chart: sets the lines, grid style, legend etc
* @brief ChartWidget::initChart
*/
void ChartWidget::prepareChart(){
QCustomPlot *customPlot = ui->chart;
customPlot->clearGraphs();
graphs.clear();
switch(mode){
case 0:
customPlot->xAxis->setLabel("r");
customPlot->yAxis->setLabel("Concentration");
case 1:
customPlot->xAxis->setLabel("r");
customPlot->yAxis->setLabel("Number of particles");
graphs.append(customPlot->addGraph());
graphs.append(customPlot->addGraph());
graphs[0]->setPen(QPen(Qt::blue,1));
graphs[1]->setPen(QPen(Qt::red,1));
break;
case 2:
graphs.append(customPlot->addGraph());
graphs[0]->setPen(QPen(Qt::blue,1));
customPlot->xAxis->setLabel("r");
customPlot->yAxis->setLabel("Potential, eV");
}
// set some pens, brushes and backgrounds:
customPlot->xAxis->setBasePen(QPen(Qt::black, 1));
customPlot->yAxis->setBasePen(QPen(Qt::black, 1));
customPlot->xAxis->setTickPen(QPen(Qt::black, 1));
customPlot->yAxis->setTickPen(QPen(Qt::black, 1));
customPlot->xAxis->setSubTickPen(QPen(Qt::blue, 1));
customPlot->yAxis->setSubTickPen(QPen(Qt::blue, 1));
customPlot->xAxis->setTickLabelColor(Qt::black);
customPlot->yAxis->setTickLabelColor(Qt::black);
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->setUpperEnding(QCPLineEnding::esSpikeArrow);
customPlot->yAxis->setUpperEnding(QCPLineEnding::esSpikeArrow);
}
示例8: UpdateGraph
void CurrencyPane::UpdateGraph(const QMap<double, double> map) {
QCustomPlot* customPlot = ui->plotWidget;
if (map.size() < 2) {
customPlot->hide();
return;
}
if (customPlot->isHidden()) {
customPlot->show();
}
//customPlot->setBackground(Qt::transparent);
double lastDate = map.lastKey();
double weekAgo = QDateTime(QDate::currentDate()).addDays(-7).toTime_t();
double highestVal = 0;
if (!map.isEmpty()) {
highestVal = from(map.values().toVector().toStdVector()).max();
}
if (customPlot->graphCount() > 0) {
customPlot->removeGraph(0);
}
customPlot->addGraph();
customPlot->graph()->setName("Net Worth");
QPen pen;
pen.setColor(QColor(0, 0, 255, 200));
customPlot->graph()->setLineStyle(QCPGraph::lsLine);
customPlot->graph()->setPen(pen);
customPlot->graph()->setBrush(QBrush(QColor(255/4.0,160,50,150)));
customPlot->graph()->setData(map.keys().toVector(), map.values().toVector());
// configure bottom axis to show date and time instead of number:
customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
customPlot->xAxis->setDateTimeFormat("ddd");
// set a more compact font size for bottom and left axis tick labels:
customPlot->xAxis->setTickLabelFont(QFont(QFont().family(), 8));
customPlot->yAxis->setTickLabelFont(QFont(QFont().family(), 8));
// set axis labels:
customPlot->xAxis->setLabel("Date");
customPlot->yAxis->setLabel("Total Worth in Chaos");
// make top and right axes visible but without ticks and labels:
customPlot->xAxis2->setVisible(true);
customPlot->yAxis2->setVisible(true);
customPlot->xAxis2->setTicks(false);
customPlot->yAxis2->setTicks(false);
customPlot->xAxis2->setTickLabels(false);
customPlot->yAxis2->setTickLabels(false);
// set axis ranges to show all data:
customPlot->xAxis->setRange(weekAgo, lastDate);
customPlot->yAxis->setRange(0, highestVal);
// show legend:
customPlot->legend->setVisible(true);
}
示例9: Demo
void BasicGraph::Demo()
{
QCustomPlot* customPlot = ui.basicGraph;
// add two new graphs and set their look:
customPlot->addGraph();
customPlot->graph(0)->setPen(QPen(Qt::blue)); // line color blue for first graph
customPlot->graph(0)->setBrush(QBrush(QColor(0, 0, 255, 20))); // first graph will be filled with translucent blue
customPlot->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<double> x(250), y0(250), y1(250);
for (int i = 0; i<250; ++i)
{
x[i] = i;
y0[i] = exp(-i / 150.0)*cos(i / 10.0); // exponentially decaying cosine
y1[i] = exp(-i / 150.0); // exponential envelope
}
// configure right and top axis to show ticks but no labels:
// (see QCPAxisRect::setupFullAxesBox for a quicker method to do this)
customPlot->xAxis2->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);
ExternalReplot();
}
示例10: createWaveFormPic
void Record::createWaveFormPic(Ffmpeg_t *ffmpeg, QString recortPath) {
std::pair<std::vector<double>, std::vector<double> > dataWaveForm = ffmpeg->getSamplesForWaveformPlotting(recortPath + "/" + m_Name);
QCustomPlot Plotter;
Plotter.setBackground(QBrush(Qt::transparent) );
Plotter.xAxis->setVisible(false);
Plotter.yAxis->setVisible(false);
Plotter.axisRect()->setAutoMargins(QCP::msNone);
Plotter.axisRect()->setMargins(QMargins(0, 5, 0, 5));
QCPGraph *Waveform = Plotter.addGraph();
Waveform->setPen(QPen(Qt::green) );
if (!Waveform)
{
qDebug("addGraph failed\n");
}
QVector<double> Amplitudes(QVector<double>::fromStdVector(dataWaveForm.first) );
QVector<double> Time;
double CurrentTime = 0;
auto TimeSlotCount = Amplitudes.size();
for (int64_t i = 1; i < TimeSlotCount; i++)
{
Time.append(CurrentTime);
CurrentTime += 0.5;
}
Waveform->setData(Time, Amplitudes);
Plotter.xAxis->setRange(0, Time.back() );
Plotter.yAxis->setRange(SHRT_MIN, SHRT_MAX);
QByteArray ByteArray;
QBuffer Buffer(&ByteArray);
Buffer.open(QBuffer::WriteOnly);
uint32_t time = m_EndTime - m_StartTime;
for (int i = 1; i < 10000; i*=10) {
Plotter.toPixmap(time/(i), this->height()).save(&Buffer, "PNG", 0);
//Plotter.saveJpg(recortPath + "/plot" + QString::number(m_Id) + QString::number(i) + ".jpg", time/(i), this->height());
QPixmap Pixmap;
Pixmap.loadFromData(ByteArray, "PNG");
v_PixWaves.append(Pixmap);
ByteArray.clear();
Buffer.reset();
}
Buffer.close();
qDebug() << m_WavePic->margin();
// místo 2 podle toho jaký zoom
m_WavePic->setPixmap(v_PixWaves[2]);
}
示例11: updatePlots
void MainWindow::updatePlots()
{
for(int k=0;k<plotList->size();k++)
{
QCustomPlot *customPlot = ui->plotArea->findChild<QCustomPlot*>(plotList->value(k));
customPlot->addGraph();
// customPlot->graph(0)->addData(i,i*2);
customPlot->xAxis->setLabel("x");
customPlot->yAxis->setLabel("y");
// set axes ranges, so we see all data:
customPlot->xAxis->setRange(-100, 100);
customPlot->yAxis->setRange(-1000, 1000);
customPlot->replot();
}
}
示例12: createGraph
void Graph::createGraph(const std::string& name, QColor color) {
if (name.length() > 255) {
std::cout << "LiveGrapher: Graph::createGraph(): "
<< "name exceeds 255 characters" << std::endl;
return;
}
m_dataSets.emplace_back();
QCustomPlot* customPlot = m_window->m_ui->plot;
customPlot->addGraph();
customPlot->graph()->setName(QString::fromUtf8(name.c_str()));
customPlot->graph()->setAntialiasedFill(false);
customPlot->setNoAntialiasingOnDrag(true);
QPen pen(color);
customPlot->graph()->setPen(pen);
}
示例13: drawPlot
void Snakes::drawPlot(std::vector<double> inputX, std::vector<double> inputY) {
QCustomPlot *customPlot = new QCustomPlot();
customPlot->resize(500, 500);
QVector<double> x = QVector<double>::fromStdVector(inputX);
QVector<double> y = QVector<double>::fromStdVector(inputY);
customPlot->addGraph();
customPlot->graph(0)->setData(x, y);
customPlot->xAxis->setLabel("x");
customPlot->yAxis->setLabel("y");
customPlot->xAxis->setRange(inputX.front(), inputX.back());
customPlot->yAxis->setRange(inputY.front(), inputY.back());
customPlot->replot();
customPlot->show();
}
示例14: x
void MainWindow::maximizarGrafico1(QMouseEvent* e) {
QVector<double> x(100);
QVector<double> y(100);
wgraficos *w = new wgraficos();
w->exec();
QCustomPlot * graph = w->getDatos();
graph->addGraph();
for (int i = 0; i < 100; ++i) {
x[i] = i;
y[i] = rand();
}
graph->graph(0)->setData(x,y);
graph->replot();
}
示例15: runOptimization
void MainWindow::runOptimization() {
if (m_CostFunc.IsNull() || g_pointList.size() == 0) {
return;
}
OptimizerParameters initialParams;
ConvertListOfPointVectorsToParameters(g_pointList, initialParams);
OptimizerProgress::Pointer progress = OptimizerProgress::New();
progress->SetParticlesHistory(&g_pointHistory);
OptimizerParameters result;
if (ui.optiCG->isChecked()) {
result = optimizeByFRPR(m_CostFunc, initialParams, progress);
} else if (ui.optiGD->isChecked()) {
result = optimizeByGD(m_CostFunc, initialParams, progress);
} else if (ui.optiLBFGS->isChecked()) {
result = optimizeByLBFGS(m_CostFunc, initialParams, progress);
}
// draw cost function
ConvertParametersToListOfPointVectors(result, g_pointList.size(), g_pointList[0].size(), g_pointList);
QVector<double> x(g_costHistory.size()), y(g_costHistory.size()); // initialize with entries 0..100
for (int i = 0; i < x.count(); ++i)
{
x[i] = i;
y[i] = g_costHistory[i];
}
QCustomPlot* customPlot = ui.customPlot;
customPlot->clearGraphs();
// create graph and assign data to it:
customPlot->addGraph();
customPlot->graph(0)->setData(x, y);
customPlot->rescaleAxes();
// give the axes some labels:
customPlot->xAxis->setLabel("iteration");
customPlot->yAxis->setLabel("cost");
customPlot->replot();
updateScene();
}