本文整理汇总了C++中QCustomPlot::graph方法的典型用法代码示例。如果您正苦于以下问题:C++ QCustomPlot::graph方法的具体用法?C++ QCustomPlot::graph怎么用?C++ QCustomPlot::graph使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QCustomPlot
的用法示例。
在下文中一共展示了QCustomPlot::graph方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addToPlot
void MainWindow::addToPlot(std::vector<double> *x, std::vector<double> *y, int graphNum, AlgorithmFactory::ALGORITHM alg)
{
QCustomPlot *cp = this->ui->plotter;
QVector<double> __x = QVector<double>::fromStdVector(*x);
QVector<double> __y = QVector<double>::fromStdVector(*y);
cp->graph(graphNum)->setData(__x, __y);
switch (alg)
{
default:
case AlgorithmFactory::SPHERE:
cp->graph(graphNum)->setName("Esfera");
break;
case AlgorithmFactory::ROTATED_RASTRIGIN:
cp->graph(graphNum)->setName("Rot Rastrigin");
break;
case AlgorithmFactory::ROSENBROCK:
cp->graph(graphNum)->setName("Rosenbrock");
break;
}
cp->rescaleAxes(true);
cp->replot();
}
示例2: 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;
}
示例3: 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);
}
示例4: 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);
}
示例5: SetRange
void SetRange(QCustomPlot& plot, int index, QVariantMap range, QCPAxis::AxisType type)
{
auto g = plot.graph(index);
auto it = range.find("lo");
if (it != range.end())
{
switch (type)
{
case QCPAxis::atLeft:
g->valueAxis()->setRangeLower(it->toReal());
break;
case QCPAxis::atBottom:
g->keyAxis()->setRangeLower(it->toReal());
break;
}
}
it = range.find("up");
if (it != range.end())
{
switch (type)
{
case QCPAxis::atLeft:
g->valueAxis()->setRangeUpper(it->toReal());
break;
case QCPAxis::atBottom:
g->keyAxis()->setRangeUpper(it->toReal());
break;
}
}
}
示例6: 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();
}
示例7: 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()));
}
示例8: 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);
}
示例9: compassMotCalibration
void CompassMotorCalibrationDialog::compassMotCalibration(mavlink_compassmot_status_t *compassmot_status)
{
if (!m_uasInterface)
return; // no active UAS.
QCustomPlot* customPlot = ui->customPlot;
int index = compassmot_status->throttle/10;
customPlot->graph(GRAPH_ID_CURRENT)->addData(index, compassmot_status->current);
customPlot->graph(GRAPH_ID_INTERFERENCE)->addData(index, compassmot_status->interference);
customPlot->replot();
x_scalar = compassmot_status->CompensationX;
y_scalar = compassmot_status->CompensationY;
z_scalar = compassmot_status->CompensationZ;
}
示例10: 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()));
}
}
示例11: refreshLog
void viewGVpropertieslayout::refreshLog(logData * log) {
if (log->setupFromXML()) {
// find graphs from this log
// get a list of the MDI windows
QList<QMdiSubWindow *> subWins = viewGV->mdiarea->subWindowList();
// loop and extract the plot
for (int i = 0; i < subWins.size(); ++i) {
QCustomPlot * currPlot = (QCustomPlot *) subWins[i]->widget();
// loop through graphs in the plot
for (int j = 0; j < currPlot->graphCount(); ++j) {
// if the graph is from this log
if (currPlot->graph(j)->property("source").toString() == log->logFileXMLname) {
// extract remaining graph data
QString type = currPlot->graph(j)->property("type").toString();
if (type == "linePlot") {
// get index
int index = currPlot->graph(j)->property("index").toInt();
log->plotLine(currPlot, index, j);
} else if (type == "rasterPlot") {
// get indices
QList < QVariant > indices = currPlot->graph(j)->property("indices").toList();
log->plotRaster(currPlot, indices, j);
}
}
}
}
} else
return;
}
示例12: addChartPoints
void ChartPage::addChartPoints()
{
if (this->buildingChart)
return;
this->buildingChart=true;
ClientModel *model = this->clientModel;
QCustomPlot *customPlot = ui->chartBlock;
// generate some data:
QVector<double> x(250), y(250);
int maxBlocks = 0;
maxBlocks = model->getNumBlocks() - this->lastBlockHeight;
if (maxBlocks == 0)
return;
if (maxBlocks > 250)
{
maxBlocks = 250;
} else {
this->timer->stop();
}
int i;
for (i = 0; i < maxBlocks; i++)
{
CBlock blk = model->getBlock(i + this->lastBlockHeight);
CBlockIndex* cIndex = model->getBlockIndex(i + this->lastBlockHeight);
x[i]=blk.GetBlockTime();
y[i]=model->getDiff(cIndex);
}
if (this->lastBlockHeight > 0) {
customPlot->graph(0)->addData(x, y);
} else {
customPlot->graph(0)->setData(x, y);
}
customPlot->xAxis->setRange(x[i-1] - rangeChoice, x[i-1]);
customPlot->replot();
this->buildingChart=false;
this->lastBlockHeight += i;
}
示例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: 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();
}
示例15: 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();
}