void Window::plotHistogram(QVector<double> key, QVector<double> nonEq, QVector<double> eqValue, QVector<double> lutValue) { QCustomPlot *histogramPlot = ui->histogramPlot; histogramPlot->clearGraphs(); // Non Equalized QCPBars *nonEqHistBars = new QCPBars(histogramPlot->xAxis, histogramPlot->yAxis); histogramPlot->addPlottable(nonEqHistBars); nonEqHistBars->setWidth(1); nonEqHistBars->setData(key, nonEq); nonEqHistBars->setPen(Qt::NoPen); nonEqHistBars->setBrush(QColor(10, 140, 70, 160)); // // Equalized // QCPBars *eqHistBars = new QCPBars(histogramPlot->xAxis, histogramPlot->yAxis); // histogramPlot->addPlottable(eqHistBars); // eqHistBars->setWidth(1); // eqHistBars->setData(key, eqValue); // eqHistBars->setPen(Qt::NoPen); // eqHistBars->setBrush(QColor(10, 100, 50, 70)); //// eqHistBars->moveAbove(eqHistBars); // // LUT // QCPGraph *lut = histogramPlot->addGraph(); // lut->setData(key, lutValue); // lut->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssNone, QPen(Qt::black, 1.5), QBrush(Qt::white), 9)); // lut->setLineStyle(QCPGraph::lsStepCenter); // lut->setPen(QPen(QColor(120, 120, 120), 2)); histogramPlot->replot(); histogramPlot->rescaleAxes(); }
void viewGVpropertieslayout::removeAllGraphs() { // first get a pointer to the current plot! QCustomPlot * currPlot = (QCustomPlot *) currentSubWindow->widget(); currPlot->clearGraphs(); currPlot->replot(); }
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; }
void MainWindow::on_listView_clicked(const QModelIndex &index) { //QModelIndex a = ui->listView->selectedIndexes().back(); QVariant selected = dataModel->compNameList->data(index,Qt::DisplayRole); dataModel->dataViewComp = selected.toString(); QVector<double> dataViewPrice = dataModel->priceBuff.value(selected.toString()); QVector<double> xval; QVector<double> baseVal; if(dataViewPrice.empty()) return; double min = dataViewPrice[0]; for(auto &i : dataViewPrice) min = std::fmin(min,i); for(int i = 0; i<dataViewPrice.size(); i++){ xval<<i; baseVal<<min; } QCustomPlot* p = ui->qcpDataView;; p->clearGraphs(); QCPGraph* timeline = new QCPGraph(p->xAxis,p->yAxis); timeline->addData(xval,dataViewPrice); QCPGraph* base = new QCPGraph(p->xAxis,p->yAxis); base->setData(xval,baseVal); p->addPlottable(timeline); p->addPlottable(base); timeline->setChannelFillGraph(base); timeline->setPen(QPen(QColor(0,0,0,0))); timeline->setBrush(QColor(0,0,255,100)); //QVector<double> ticks; QVector<QString> labels; int L = this->dataModel->dateBuff.values()[0].size()-1; int len = 6; float step = (float)L/(float)len; for(int i = 0; i<= len; i++){ labels<<this->dataModel->dateBuff.values()[0][i*step].toString("MM/yy"); } p->xAxis->setTickVectorLabels(labels); p->xAxis->setAutoTicks(true); p->xAxis->setAutoTickLabels(false); p->xAxis->setTickLabelRotation(-60); //p->xAxis->setSubTickCount(0); //p->xAxis->setTickLength(0, len-1); p->xAxis->grid()->setVisible(true); //p->xAxis->setRange(0, len-2); //p->xAxis->setTickVector(ticks); p->rescaleAxes(); p->replot(); }
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(); }
/** 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); }
bool FeaturePlot::plot(){ if( !initialized ) return false; QCustomPlot *plot = ui->plot; //Clear any previous graphs plot->clearGraphs(); const unsigned int M = data.getNumSamples(); const unsigned int K = data.getNumClasses(); const unsigned int N = data.getNumDimensions(); GRT::Vector< GRT::MinMax > ranges = data.getRanges(); GRT::Vector< unsigned int > classLabels = data.getClassLabels(); GRT::Vector< GRT::ClassTracker > classTracker = data.getClassTracker(); double minRange = GRT::grt_numeric_limits<double>::max(); double maxRange = -minRange; //Add a new graph for each class for(unsigned int k=0; k<K; k++){ const unsigned int numSamplesInClass = classTracker[k].counter; if( numSamplesInClass > 0 ){ QVector< double > x( numSamplesInClass ); QVector< double > y( numSamplesInClass ); plot->addGraph(); plot->graph(k)->setPen( QPen( classColors[ k % classColors.size() ] ) ); plot->graph(k)->setLineStyle( QCPGraph::lsNone ); plot->graph(k)->setScatterStyle( QCPScatterStyle(QCPScatterStyle::ssCross, 4) ); unsigned int index = 0; for(unsigned int i=0; i<M; i++) { if( data[i].getClassLabel() == classTracker[k].classLabel ){ x[ index ] = data[i][ axisIndexX ]; y[ index ] = data[i][ axisIndexY ]; index++; for(unsigned int j=0; j<N; j++){ if( data[i][j] > maxRange ){ maxRange = data[i][j]; }else if( data[i][j] < minRange ){ minRange = data[i][j]; } } } } // pass data points to graphs: plot->graph( k )->setData(x, y); } } //Add 20% to the min and max range minRange += minRange * 0.2; maxRange += maxRange * 0.2; plot->xAxis->setVisible( true ); plot->xAxis->setTickLabels( true ); plot->yAxis->setVisible( true ); plot->yAxis->setTickLabels( true ); plot->xAxis->setLabel( QString::fromStdString("X Axis Index: " + GRT::Util::toString(axisIndexX)) ); plot->yAxis->setLabel( QString::fromStdString("Y Axis Index: " + GRT::Util::toString(axisIndexY)) ); plot->xAxis->setRange(minRange, maxRange); plot->yAxis->setRange(minRange, maxRange); plot->replot(); plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); return true; }
void convert::force(int nn,double D,double rho,double Cd,double Cm){ // Define Pi // const double PI = 4.0*atan(1.0); // To cover-up for previous lazyness are we now making local // copies of the fields we need - sorry! // std::vector<double> tmp_; tmp_.resize(nt); for (int i=0;i<nt;i++){ tmp_[i] = eta[i*nx*ny+nn]; } // deta/dt // std::vector<double> detadt; detadt.resize(nt); gradient(detadt,tmp_,dt,nt); // dz/dt // Double2d dzdt(boost::extents[nz][nt]); for (int k=0;k<nz;k++){ for (int i=0;i<nt;i++){ dzdt[k][i] = detadt[i]*sigma[k]; } } // du/dt on the sigma grid // Double2d dudt(boost::extents[nz][nt]); for (int k=0;k<nz;k++){ for (int i=0;i<nt;i++){ tmp_[i] = u[i*nx*ny*nz+nn*nz+k]; } gradient(&dudt[k][0],tmp_,dt,nt); // To-do: this is super sluppy and error prone } // Acceleration // Double2d acc(boost::extents[nz][nt]); for (int k=0;k<nz;k++){ for (int i=0;i<nt;i++){ acc[k][i] = dudt[k][i]-uz[i*nx*ny*nz+nn*nz+k]*dzdt[k][i]; } } // The inline force // double dz,Fd,Fi; int index; F.resize(nt); for (int i=0;i<nt;i++){ F[i] = 0; for (int k=1;k<nz-1;k++){// we ignore the ghost points index = i*nx*ny*nz+nn*nz+k; dz = (sigma[k+1]-sigma[k])*(eta[i*nx*ny+nn]+h[nn]); Fd = 0.5*rho*Cd*D*(u[index]*std::abs(u[index])+u[index+1]*std::abs(u[index+1]))/2; Fi = rho*Cm*(PI/4)*pow(D,2)*(acc[k][i]+acc[k+1][i])/2; F[i] += (Fd+Fi)*dz; } } QFileInfo fileInfo = QFileInfo(fileName); std::ofstream morisonForce; morisonForce.open(fileInfo.baseName().toLatin1() + ".force"); morisonForce << "time F" << std::endl; QVector<double> QV_t,QV_F; QV_t.resize(nt); QV_F.resize(nt); for (int i=1;i<nt-1;i++){ morisonForce << std::setiosflags(std::ios::fixed) << std::setprecision(10) << t[i] << " " << F[i] << std::endl; QV_t[i] = t[i]; QV_F[i] = F[i]; } morisonForce.close(); // plot solution QCustomPlot *cPlot = new QCustomPlot; QWidget *plotWindow = new QWidget; QHBoxLayout *plotWindow_layout = new QHBoxLayout; plotWindow_layout->addWidget(cPlot); plotWindow->setLayout(plotWindow_layout); plotWindow->resize(800,400); plotWindow->show(); cPlot->clearGraphs(); cPlot->addGraph(); cPlot->graph()->setData(QV_t,QV_F); cPlot->xAxis->setLabel("Time, t s"); cPlot->yAxis->setLabel("Inline force, F N"); QVector<double>::iterator Xmin = std::min_element(QV_t.begin(), QV_t.end()); QVector<double>::iterator Xmax = std::max_element(QV_t.begin(), QV_t.end()); QVector<double>::iterator Ymin = std::min_element(QV_F.begin(), QV_F.end()); QVector<double>::iterator Ymax = std::max_element(QV_F.begin(), QV_F.end()); cPlot->xAxis->setRange(*Xmin,*Xmax); cPlot->yAxis->setRange(*Ymin,*Ymax); cPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); cPlot->replot(); }