void MainWindow::setupDateTest(QCustomPlot *customPlot) { #if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime); QCPGraph *g = customPlot->addGraph(); g->addData(QDateTime(QDate(350,5,21), QTime(0, 0)).toMSecsSinceEpoch()/1000.0, 1); g->addData(QDateTime(QDate(650,5,21), QTime(0, 0)).toMSecsSinceEpoch()/1000.0, 2); g->addData(QDateTime(QDate(740,5,21), QTime(0, 0)).toMSecsSinceEpoch()/1000.0, 4); g->addData(QDateTime(QDate(1000,5,21), QTime(0, 0)).toMSecsSinceEpoch()/1000.0, 8); g->rescaleAxes(); #endif }
void BodeWidget::addBodePlot(BodeData *data, const QString& name){ QCPGraph* dbGraph = dbPlot->addGraph(); QCPGraph* paGraph = paPlot->addGraph(); dbGraph->setData(data->at(0), data->at(1)); paGraph->setData(data->at(0), data->at(2)); dbGraph->setName(name); paGraph->setName(name); dbGraph->setPen(QPen(QColor::fromHsv(hue, 255, 255, 192))); paGraph->setPen(QPen(QColor::fromHsv(hue, 255, 255, 192))); paGraph->setVisible(false); dbGraph->rescaleAxes(); paGraph->rescaleAxes(); hue += 17; hue %= 360; this->paGraphMap[dbGraph] = paGraph; }
void ScatterPlotWidget::updatePlot(){ ui->customPlot->clearGraphs();//clearPlottables(); if(selectedTrips == NULL) return; // ExtraField field; switch(attrib1){ case(FARE_AMOUNT): ui->customPlot->xAxis->setLabel(QString::fromStdString("Fare Amount (US$)")); break; case(TIP_AMOUNT): ui->customPlot->xAxis->setLabel(QString::fromStdString("Tip Amount (US$)")); break; case(DURATION): ui->customPlot->xAxis->setLabel(QString::fromStdString("Duration (min)")); break; case(DISTANCE): ui->customPlot->xAxis->setLabel(QString::fromStdString("Distance (mi)")); break; case(TOLL_AMOUNT): ui->customPlot->xAxis->setLabel(QString::fromStdString("Toll Amount (US$)")); break; case(AVG_SPEED): ui->customPlot->xAxis->setLabel(QString::fromStdString("Avg Speed (mi/h)")); break; case(TIME_OF_DAY): ui->customPlot->xAxis->setLabel(QString::fromStdString("Hour of day")); break; case(FIELD1): field = Global::getInstance()->getExtraField(0); ui->customPlot->xAxis->setLabel(field.axisLabel); break; case(FIELD2): field = Global::getInstance()->getExtraField(1); ui->customPlot->xAxis->setLabel(field.axisLabel); break; case(FIELD3): field = Global::getInstance()->getExtraField(2); ui->customPlot->xAxis->setLabel(field.axisLabel); break; case(FIELD4): field = Global::getInstance()->getExtraField(3); ui->customPlot->xAxis->setLabel(field.axisLabel); break; default: assert(false); break; } // switch(attrib2){ case(FARE_AMOUNT): ui->customPlot->yAxis->setLabel(QString::fromStdString("Fare Amount (US$)")); break; case(TIP_AMOUNT): ui->customPlot->yAxis->setLabel(QString::fromStdString("Tip Amount (US$)")); break; case(DURATION): ui->customPlot->yAxis->setLabel(QString::fromStdString("Duration (min)")); break; case(DISTANCE): ui->customPlot->yAxis->setLabel(QString::fromStdString("Distance (mi)")); break; case(TOLL_AMOUNT): ui->customPlot->yAxis->setLabel(QString::fromStdString("Toll Amount (US$)")); break; case(AVG_SPEED): ui->customPlot->yAxis->setLabel(QString::fromStdString("Avg Speed (mi/h)")); break; case(TIME_OF_DAY): ui->customPlot->yAxis->setLabel(QString::fromStdString("Hour of day")); break; case(FIELD1): field = Global::getInstance()->getExtraField(0); ui->customPlot->yAxis->setLabel(field.axisLabel); break; case(FIELD2): field = Global::getInstance()->getExtraField(1); ui->customPlot->yAxis->setLabel(field.axisLabel); break; case(FIELD3): field = Global::getInstance()->getExtraField(2); ui->customPlot->yAxis->setLabel(field.axisLabel); break; case(FIELD4): field = Global::getInstance()->getExtraField(3); ui->customPlot->yAxis->setLabel(field.axisLabel); break; default: assert(false); break; } // bool buildGlobalPlot = (selectionGraph->isEmpty()); set<Group> groups; map<Group,vector<SelectionGraphNode*> > mapGroupToNodes; map<Group,vector<SelectionGraphEdge*> > mapGroupToEdges; set<Group>::iterator groupIterator; selectionGraph->groupNodesAndEdgeByColor(groups,mapGroupToNodes,mapGroupToEdges); map<Group,QCPGraph*> mapGroupGraph; // set<Group> notEmptyGroups; map<Group,vector<SelectionGraphNode*> > tempMapGroupToNodes; if(buildGlobalPlot){ QPen pen; QCPGraph* graph = ui->customPlot->addGraph(); QColor color(0,0,0); mapGroupGraph[Group(color)] = graph; color.setAlphaF(0.05); pen.setColor(color); graph->setPen(pen); graph->setLineStyle(QCPGraph::lsNone); graph->setScatterStyle(QCP::ssDisc); graph->setScatterSize(10); } else{ // for(groupIterator = groups.begin() ; groupIterator != groups.end() ; ++groupIterator){ vector<SelectionGraphNode*> &groupNodes = mapGroupToNodes[*groupIterator]; vector<SelectionGraphNode*> validGroupNodes; int numGroupNodes = groupNodes.size(); for(int i = 0 ; i < numGroupNodes ; ++i){ SelectionGraphNode* node = groupNodes.at(i); if(node->inDegree() + node->outDegree() == 0) validGroupNodes.push_back(node); } vector<SelectionGraphEdge*> &groupEdges = mapGroupToEdges[*groupIterator]; if(groupEdges.size() + validGroupNodes.size() > 0){ notEmptyGroups.insert(*groupIterator); tempMapGroupToNodes[*groupIterator] = validGroupNodes; } } groups.clear(); groups = notEmptyGroups; mapGroupToNodes.clear(); mapGroupToNodes = tempMapGroupToNodes; // for(groupIterator = groups.begin() ; groupIterator != groups.end() ; ++groupIterator){ QPen pen; QCPGraph* graph = ui->customPlot->addGraph(); graph->setLineStyle(QCPGraph::lsNone); graph->setScatterStyle(QCP::ssDisc); graph->setScatterSize(10); Group group = *groupIterator; QColor color = group.getColor(); mapGroupGraph[group] = graph; color.setAlphaF(0.3); pen.setColor(color); graph->setPen(pen); } } //int numberOfTrip = selectedTrips->size(); map<Group,pair<QVector<double>,QVector<double> > > mapGroupData; if(buildGlobalPlot){ int numberOfTrips = selectedTrips->size(); //QVector<double> x(numberOfTrips), y(numberOfTrips); QVector<double> x, y; mapGroupData[QColor(0,0,0)] = make_pair(x,y); } else{ QVector<double> x, y; for(groupIterator = groups.begin() ; groupIterator != groups.end() ; ++groupIterator){ Group group = *groupIterator; mapGroupData[group.getColor()] = make_pair(x,y); } } // add graphs with different scatter styles: KdTrip::TripSet::iterator it = selectedTrips->begin(); for (; it != selectedTrips->end(); ++it) { const KdTrip::Trip * trip = *it; QPointF coords = getCoords(trip); if(buildGlobalPlot){ pair<QVector<double>,QVector<double> > &data = mapGroupData[QColor(0,0,0)]; QVector<double> &x = data.first; QVector<double> &y = data.second; x << coords.x(); y << coords.y(); } else{ for(groupIterator = groups.begin() ; groupIterator != groups.end() ; ++groupIterator){ Group currentGroup = *groupIterator; assert(mapGroupToNodes.count(currentGroup) > 0 && mapGroupToEdges.count(currentGroup) > 0); if(tripSatisfiesConstraints(trip, mapGroupToNodes[currentGroup],mapGroupToEdges[currentGroup])){ pair<QVector<double>,QVector<double> > &data = mapGroupData[currentGroup.getColor()]; QVector<double> &x = data.first; QVector<double> &y = data.second; x << coords.x(); y << coords.y(); continue; // make sure the point is only added once } } } } if(buildGlobalPlot){ pair<QVector<double>,QVector<double> > &data = mapGroupData[QColor(0,0,0)]; QVector<double> &x = data.first; QVector<double> &y = data.second; QCPGraph* graph = mapGroupGraph[QColor(0,0,0)]; graph->setData(x, y); graph->rescaleAxes(true); } else{ for(groupIterator = groups.begin() ; groupIterator != groups.end() ; ++groupIterator){ Group currentGroup = *groupIterator; pair<QVector<double>,QVector<double> > &data = mapGroupData[currentGroup.getColor()]; QVector<double> &x = data.first; QVector<double> &y = data.second; QCPGraph* graph = mapGroupGraph[currentGroup.getColor()]; graph->setData(x, y); graph->rescaleAxes(true); } } // int numGraphs = ui->customPlot->graphCount(); for(int i = 0 ; i < numGraphs ; ++i){ ui->customPlot->graph(i)->rescaleAxes(false,true); } //ui->customPlot->yAxis->scaleRange(1.1, ui->customPlot->yAxis->range().center()); ui->customPlot->setRangeDrag(Qt::Horizontal|Qt::Vertical); ui->customPlot->setRangeZoom(Qt::Horizontal|Qt::Vertical); ui->customPlot->setInteractions(QCustomPlot::iRangeDrag | QCustomPlot::iRangeZoom | QCustomPlot::iSelectAxes | QCustomPlot::iSelectLegend | QCustomPlot::iSelectPlottables | QCustomPlot::iSelectTitle); // ui->customPlot->replot(); }