void Curves::resamples() { setTitleX(); foreach(int i, curves.keys()){ if(i >= file->size()){ delete curves.take(i); } else{ QwtPlotCurve* curve = curves.value(i); curve->setSamples( file->samples(iX), file->samples(i) ); } } ownerOuts->repaint(); if(in){ if(iIn >= file->size()){ iIn = -1; delete in; in = NULL; } else{ in->setSamples( file->samples(iX), file->samples(iIn) ); } static_cast<InPlot*>(ownerIn)->clearInterval(); } }
void Plot::add() { Q_ASSERT(plotWidget && x && y && x->size()==y->size()); setIntervals(); for (int i = 0; i < intervals.size(); ++i) { QwtPlotCurve *curve = new QwtPlotCurve(yLegend); curve->setItemAttribute(QwtPlotItem::Legend, showLegend && i==0); plotWidget->addCurve(curve); if (type == Trace::Symbols) { curve->setStyle(QwtPlotCurve::NoCurve); } if (type == Trace::Symbols || type == Trace::Both) { Q_ASSERT(symbol); curve->setSymbol(symbol); } if (type == Trace::Line || type == Trace::Both) { curve->setPen(pen); } Interval iv = intervals[i]; int numPoints = iv.second - iv.first + 1; if (numPoints <=0 ) Q_ASSERT(numPoints > 0); curve->setSamples(x->data() + iv.first, y->data() + iv.first, numPoints); } }
void CentralWidget::initTmpPlotAndGL() { QwtPlot *plot = new QwtPlot(this); plot->setTitle( "Plot Demo" ); plot->setCanvasBackground( Qt::white ); plot->setAxisScale( QwtPlot::yLeft, 0.0, 10.0 ); QwtPlotGrid *grid = new QwtPlotGrid(); grid->attach( plot ); QwtPlotCurve *curve = new QwtPlotCurve(); curve->setTitle( "Some Points" ); curve->setPen( Qt::blue, 4 ), curve->setRenderHint( QwtPlotItem::RenderAntialiased, true ); QPolygonF points; points << QPointF( 0.0, 4.4 ) << QPointF( 1.0, 3.0 ) << QPointF( 2.0, 4.5 ) << QPointF( 3.0, 6.8 ) << QPointF( 4.0, 7.9 ) << QPointF( 5.0, 7.1 ); curve->setSamples( points ); curve->attach( plot ); this->addTab(plot, tr("Tmp Plot")); MyGLWidget *widget = new MyGLWidget(this); this->addTab(widget, tr("Tmp OpenGL")); }
void Plot::insertCurve(Qt::Orientation o, const QColor &c, double base) { QwtPlotCurve *curve = new QwtPlotCurve(); curve->setPen(c); curve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse, Qt::gray, c, QSize(8, 8))); double x[10]; double y[sizeof(x) / sizeof(x[0])]; for ( uint i = 0; i < sizeof(x) / sizeof(x[0]); i++ ) { double v = 5.0 + i * 10.0; if ( o == Qt::Horizontal ) { x[i] = v; y[i] = base; } else { x[i] = base; y[i] = v; } } curve->setSamples(x, y, sizeof(x) / sizeof(x[0])); curve->attach(this); }
void Plot::populate() { QwtPlotGrid *grid = new QwtPlotGrid(); grid->setMinorPen( Qt::black, 0, Qt::DashLine ); grid->enableXMin( true ); grid->attach( this ); QwtPlotCurve *curve = new QwtPlotCurve(); curve->setTitle("Some Points"); curve->setPen( Qt::blue, 4 ), curve->setRenderHint( QwtPlotItem::RenderAntialiased, true ); QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::yellow ), QPen( Qt::red, 2 ), QSize( 8, 8 ) ); curve->setSymbol( symbol ); QPolygonF points; points << QPointF( 10.0, 4.4 ) << QPointF( 100.0, 3.0 ) << QPointF( 200.0, 4.5 ) << QPointF( 300.0, 6.8 ) << QPointF( 400.0, 7.9 ) << QPointF( 500.0, 7.1 ) << QPointF( 600.0, 7.9 ) << QPointF( 700.0, 7.1 ) << QPointF( 800.0, 5.4 ) << QPointF( 900.0, 2.8 ) << QPointF( 1000.0, 3.6 ); curve->setSamples( points ); curve->attach( this ); }
QwtPlotCurve * PlotViewWidget::addCurveData(WaveformData *curveData, bool secondary, QColor col) { maWaveformData << curveData; QwtPlotCurve *waveCurve = new QwtPlotCurve("dummy"); waveCurve->setRenderHint(QwtPlotItem::RenderAntialiased); waveCurve->setPen(QPen(col)); waveCurve->setSamples( curveData ); maCurves << waveCurve; waveCurve->attach(this); if( !mSecondaryAxis || maCurves.length() == 0 ) // no secondary axis or just one plot { replot(); setAxisScaleDiv(QwtPlot::yRight, axisScaleDiv(QwtPlot::yLeft)); replot(); } else { if(secondary) { setAxisAutoScale(QwtPlot::yRight); waveCurve->setYAxis(QwtPlot::yRight); } else { waveCurve->setYAxis(QwtPlot::yLeft); } } repaint(); return waveCurve; }
void HistoricPlot::addCurve(quint32 idVariable, std::vector<VariablePoint> data) { m_zoomer->setZoomBase(true); QwtPlotCurve *c = new QwtPlotCurve(QString("id : %1").arg(idVariable)); c->setPen( QColor(qrand() % 255,qrand() % 255,qrand() % 255), 2 ), c->setRenderHint( QwtPlotItem::RenderAntialiased, true ); QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::yellow ), QPen( Qt::red, 2 ), QSize( 5, 5 ) ); c->setSymbol( symbol ); QVector<VariablePoint> d2 = QVector<VariablePoint>::fromStdVector(data); QVector<QPointF> cleanData; for (int i = 0; i < data.size(); ++i) { VariablePoint vp = d2.at(i); qDebug() << QString("ID: %1, VALUE: %2").arg(vp.idVariable()).arg(vp.value().toDouble()); if (vp.value().type() == QVariant::Double) cleanData.append(QPointF(QwtDate::toDouble(QDateTime::fromMSecsSinceEpoch(vp.timeStamp())), vp.value().toDouble())); else cleanData.append(QPointF(QwtDate::toDouble(QDateTime::fromMSecsSinceEpoch(vp.timeStamp())), (double)vp.value().toLongLong())); } c->setSamples(cleanData); c->attach(this); }
void Plot::drawDots(QVector< QVector<struct numCluster> > data, double n, double k, int index, int size, int number) { int j, l; QPolygonF points; QwtPlotCurve *curve; QwtSymbol *symbol; points.clear(); curve = new QwtPlotCurve();//QString("y = norm%1(x)").arg(index)); curve->setItemAttribute(QwtPlotItem::Legend, false); curve->setStyle( QwtPlotCurve::Dots ); for (l = 0; l < data.size(); l++){ if (data[l][number].cluster == index){ // ПЕРЕДЕЛАТЬ если возможно!!! Нужно, чтобы он печатал сразу для всех кластеров одной л.п. if (index == 0 && data[l][number].number < n){ points << QPointF(data[l][number].number, 1); }else if (index == size - 1 && data[l][number].number > n){ points << QPointF(data[l][number].number, 1); }else{ points << QPointF(data[l][number].number, func_normal(data[l][number].number,n,k)); } //std::cout << index << "data = " << data[l][i].number << std::endl; } } curve->setSamples(points); switch (index % 5){ case 0: symbol = new QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::yellow ), QPen( Qt::red, 1 ), QSize( 8, 8 ) ); curve->setSymbol(symbol); break; case 1: symbol = new QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::green ), QPen( Qt::red, 1 ), QSize( 8, 8 ) ); curve->setSymbol(symbol); break; case 2: symbol = new QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::cyan ), QPen( Qt::red, 1 ), QSize( 8, 8 ) ); curve->setSymbol(symbol); break; case 3: symbol = new QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::magenta ), QPen( Qt::red, 1 ), QSize( 8, 8 ) ); curve->setSymbol(symbol); break; case 4: symbol = new QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::gray ), QPen( Qt::red, 1 ), QSize( 8, 8 ) ); curve->setSymbol(symbol); break; default: break; } curve->attach(this); this->replot(); }
void Plot::drawPoints(){ QwtPlotCurve *curvePoints; curvePoints = new QwtPlotCurve(); curvePoints->setPen(Qt::green); curvePoints->setSamples(pointsArr); curvePoints->attach(this); this->replot(); }
int main(int argc, char *argv[]) { /*const int L = 10; fftw_complex *in; fftw_complex *out; gsl_sf_bessel_k0_scaled(0.684684); fftw_plan p; in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*L); out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*L); p = fftw_plan_dft_1d(L, in, out,FFTW_FORWARD,FFTW_MEASURE); fftw_execute(p); fftw_destroy_plan(p); fftw_free(in); fftw_free(out); QApplication a(argc, argv); Ekg w; w.show(); qDebug() << "sdfsdfsd"; std::cout << "ALKO PROJEKT CPP CHLOSTA!"; return a.exec();*/ QApplication a( argc, argv ); QwtPlot plot; plot.setTitle( "Plot Demo" ); plot.setCanvasBackground( Qt::white ); plot.setAxisScale( QwtPlot::yLeft, 0.0, 10.0 ); plot.insertLegend( new QwtLegend() ); QwtPlotGrid *grid = new QwtPlotGrid(); grid->attach( &plot ); QwtPlotCurve *curve = new QwtPlotCurve(); curve->setTitle( "Some Points" ); curve->setPen( Qt::blue, 4 ), curve->setRenderHint( QwtPlotItem::RenderAntialiased, true ); QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::yellow ), QPen( Qt::red, 2 ), QSize( 8, 8 ) ); curve->setSymbol( symbol ); QPolygonF points; points << QPointF( 0.0, 4.4 ) << QPointF( 1.0, 3.0 ) << QPointF( 2.0, 4.5 ) << QPointF( 3.0, 6.8 ) << QPointF( 4.0, 7.9 ) << QPointF( 5.0, 7.1 ); curve->setSamples( points ); curve->attach( &plot ); plot.resize( 600, 400 ); plot.show(); return a.exec(); }
void Plot::drawLine(QColor color){ QwtPlotCurve *curvePoints; curvePoints = new QwtPlotCurve(); curvePoints->setPen(color); curvePoints->setSamples(pointsArr); curvePoints->attach(this); this->replot(); pointsArr.clear(); }
void MQwt::curve(var iX, var iY, var iTitle) { QwtPlotCurve* curve = new QwtPlotCurve(iTitle.str()); curve->attach(mPlot); curve->setRenderHint(QwtPlotItem::RenderAntialiased); curve->setSamples( iX.ptr<double>(), iY.ptr<double>(), std::min(iX.size(), iY.size()) ); }
void PlotWidget::AddPlotData(QString title, float plotData) { if(!_curves.contains(title)) { //QwtPointSeriesData *points = CreatePointSeriesFromArray(&plotData, 1); QwtPlotCurve *curve = new QwtPlotCurve(title); curve->setPen(QColor(255,0,0), 2.0); if(_showMarkers) { /*QwtSymbol *symbol1 = new QwtSymbol(); symbol1->setStyle(QwtSymbol::Ellipse); symbol1->setPen(QColor(Qt::black)); symbol1->setSize(4);*/ curve->setSymbol(GetDefaultMarker()); } QVector<QPointF> nData; QPointF p(0, plotData); nData.append(p); curve->setSamples(nData); curve->attach(_plot); _curves.insert(title, curve); } else { QwtPlotCurve *curve =_curves.value(title); QwtSeriesData<QPointF>* data = curve->data(); int s = data->size(); QPointF p(s, plotData); //QVector<QPointF> nData(s+1); QVector<QPointF> nData; for(int i = 0; i < s; i++) { QPointF p(data->sample(i).x(), data->sample(i).y()); nData.append(p); } nData.append(p); curve->setSamples(nData); } CheckNReplot(); }
void RTVTPlotWindow::addCurveWithDataFromChannel(QVector<qreal> frequency, QVector<qreal> amplitude, unsigned int channel) { QwtPlotCurve *curve = new QwtPlotCurve(QString("Channel " + QString::number(channel))); curve->setPen(selectPen()); curve->setSamples(frequency, amplitude); curve->setAxes(QwtPlot::xBottom, QwtPlot::yLeft); curves << curve; channelStringList << curve->title().text(); channelListStringModel->setStringList(channelStringList); }
void ConfigStabilizationWidget::replotExpo(int value, QwtPlotCurve &curve) { double x[EXPO_CURVE_POINTS_COUNT] = { 0 }; double y[EXPO_CURVE_POINTS_COUNT] = { 0 }; double factor = pow(EXPO_CURVE_CONSTANT, value); double step = 1.0 / (EXPO_CURVE_POINTS_COUNT - 1); for (int i = 0; i < EXPO_CURVE_POINTS_COUNT; i++) { double val = i * step; x[i] = val * 100.0; y[i] = pow(val, factor) * 100.0; } curve.setSamples(x, y, EXPO_CURVE_POINTS_COUNT); ui->expoPlot->replot(); }
void TheSQDMonitoring::SQDMshowqwtplot()//界面上的qwtplot控件显示 { //曲线 QwtPlotCurve * curve; //X轴 double time[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; //Y轴 double val[10] = {3, 5, 8, 7, 2, 0, 7, 9, 1}; //实例化 curve = new QwtPlotCurve("Acc_X"); //加载数据 curve->setSamples(time, val, 10); //加到plot,plot由IDE创建 ui->SQDM_Equipmentmessage_QwtPlot }
void Plot::insertCurve( const QString &title, const QColor &color, const QPolygonF &points ) { QwtPlotCurve *curve = new QwtPlotCurve(); curve->setTitle( title ); curve->setPen( color, 2 ), curve->setRenderHint( QwtPlotItem::RenderAntialiased, true ); QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::white ), QPen( color, 2 ), QSize( 8, 8 ) ); curve->setSymbol( symbol ); curve->setSamples( points ); curve->attach( this ); }
void MainWindow::setInitialTimeDisplay(int start) { std::size_t ncols = _vm["file.ncols"].as<int>(); std::size_t nrows = _vm["file.nrows"].as<int>(); //TODO: move plotting to appropiate method std::size_t numofplottedsamples = _vm["plot.num.samples"].as<int>(); _gridPlot->p->detachItems(); _gridPlot->setoffset(start); double interrowoffset = _vm["inter.row.offset"].as<double>(); for (std::size_t row=0; row<nrows; ++row){ // for (std::size_t row=0; row<1; ++row){ std::vector<double> xs(numofplottedsamples); std::vector<double> ys(numofplottedsamples); std::stringstream strst; std::string strTitle = "Row"; strst << strTitle << "-" << row; strTitle = strst.str(); QwtPlotCurve *tscurve = new QwtPlotCurve((char *)strTitle.c_str()); for (std::size_t x = 0; x < numofplottedsamples; ++x) { if (x+start<ncols){ xs[x] = (x+start)/_gridPlot->gridXpixelsperunit; //position in seconds if (_bf!=NULL) { ys[x] = row*interrowoffset + (*_bf)(row,x+start)/_gridPlot->gridYpixelsperunit; //y value of that sample } else if (_bfsi!=NULL) { ys[x] = row*interrowoffset + (*_bfsi)(row,x+start)/_gridPlot->gridYpixelsperunit; //y value of that sample } } } tscurve->setSamples(&xs[0],&ys[0],xs.size()); tscurve->setPen(QPen(Qt::black)); QwtPlotMarker *rowNameText = new QwtPlotMarker(); rowNameText->setLabel(QString(strTitle.c_str())); rowNameText->setXValue(xs[0]+0.25); rowNameText->setYValue(row*interrowoffset-0.5); rowNameText->attach(_gridPlot->p); tscurve->attach(_gridPlot->p); } _gridPlot->resetzoom(); }
void HarmPlot::addCurves() throw (QLE) { Harmonics* harmonics = new Harmonics(this->dir, this->ii); for(int i=0; i <= MAX_HARM - 2; i++) { this->data[i] = harmonics->getHarm(i+2); // begin from second harmonic if( ! this->data[i]) continue; // have not more harmonic in IR QString name = "Harmonic"; name += i; QwtPlotCurve* curve = new QwtPlotCurve(name); curve->setPen(QPen(HARM_COLORS[i])); curve->setYAxis(QwtPlot::yLeft); curve->attach(this); curve->setSamples(this->data[i]->freqs, this->data[i]->values, this->data[i]->length); } delete harmonics; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void StatsGenPlotWidget::createPowerCurve(int tableRow, float& xMax, float& yMax) { QwtPlotCurve* curve = m_PlotCurves[tableRow]; int err = 0; float alpha = m_TableModel->getDataValue(SGPowerLawTableModel::Alpha, tableRow); float k = m_TableModel->getDataValue(SGPowerLawTableModel::K, tableRow); float beta = m_TableModel->getDataValue(SGPowerLawTableModel::Beta, tableRow); int size = 256; QwtArray<float> x; QwtArray<float> y; err = StatsGen::GenPowerLawPlotData<QwtArray<float > > (alpha, k, beta, x, y, size); if (err == 1) { //TODO: Present Error Message return; } QwtArray<double> xD(size); QwtArray<double> yD(size); for (int i = 0; i < size; ++i) { // qDebug() << x[i] << " " << y[i] << "\n"; if (x[i] > xMax) { xMax = x[i]; } if (y[i] > yMax) { yMax = y[i]; } xD[i] = static_cast<double>(x[i]); yD[i] = static_cast<double>(y[i]); } #if QWT_VERSION >= 0x060000 curve->setSamples(xD, yD); #else curve->setData(xD, yD); #endif m_PlotView->setAxisScale(QwtPlot::yLeft, 0.0, yMax); m_PlotView->setAxisScale(QwtPlot::xBottom, 0.0, xMax); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void StatsGenRDFWidget::updateRDFPlot(QVector<float>& freqs) { // These are the output vectors QwtArray<double> xD(static_cast<int>(freqs.size())); QwtArray<double> yD(static_cast<int>(freqs.size())); QLocale loc = QLocale::system(); bool ok = false; float minDist = loc.toFloat(minDistLE->text(), &ok); float maxDist = loc.toFloat(maxDistLE->text(), &ok); const int numValues = freqs.size(); float increment = (maxDist - minDist) / numValues; double pos = minDist; for (qint32 i = 0; i < numValues; ++i) { xD[i] = pos; yD[i] = static_cast<double>(freqs.at(i)); pos = pos + increment; } // This will actually plot the XY data in the Qwt plot widget QwtPlotCurve* curve = m_PlotCurve; #if QWT_VERSION >= 0x060000 curve->setSamples(xD, yD); #else curve->setData(xD, yD); #endif curve->setStyle(QwtPlotCurve::Lines); //Use Antialiasing to improve plot render quality curve->setRenderHint( QwtPlotItem::RenderAntialiased, true ); QPen pen; pen.setColor(Qt::white); pen.setWidth(2); curve->setPen(pen);//Set colour and thickness for drawing the curve curve->attach(m_RDFPlot); m_RDFPlot->replot(); }
IRPlot::IRPlot(const QString& aDir, IRInfo anIi, QWidget *parent) throw (QLE) : QwtPlot(parent) { this->dir = aDir; this->ii = anIi; this->time = 0; this->amps = 0; this->setAutoReplot(false); this->setCanvasBackground(BG_COLOR); unsigned curveLength = this->calculate(); this->setAxisScale( xBottom, this->time[0], this->time[curveLength-1]); this->setAxisAutoScale( xBottom); this->setAxisScale( yLeft, -1.5, 1.5); QwtPlotGrid *grid = new QwtPlotGrid; grid->enableXMin(true); #if QWT_VERSION > 0x060000 grid->setMajorPen(QPen(MAJ_PEN_COLOR, 0, Qt::DotLine)); grid->setMinorPen(QPen(MIN_PEN_COLOR, 0 , Qt::DotLine)); #else grid->setMajPen(QPen(MAJ_PEN_COLOR, 0, Qt::DotLine)); grid->setMinPen(QPen(MIN_PEN_COLOR, 0 , Qt::DotLine)); #endif grid->attach(this); QwtPlotCurve* ampCurve = new QwtPlotCurve("IR_Plot"); ampCurve->setPen(QPen(AMP_CURVE_COLOR)); ampCurve->setYAxis(QwtPlot::yLeft); ampCurve->attach(this); ampCurve->setSamples(this->time, this->amps, curveLength); QwtPlotPanner* panner = new QwtPlotPanner(this->canvas()); panner->setMouseButton(Qt::MidButton); panner->setEnabled(true); this->setAutoReplot(true); }
QWT_ABSTRACT_SERIESITEM * MavPlot::_add_data_timeseries(const DataTimeseries<ST> * data, unsigned int plotnumber /* used for colors etc */) { /* * so we have a timeseries of type ST. We need to "translate" it for the plot, and then add it. * One problem is, that Qwt cannot plot double against float...so we need to "convert" every- * thing to double here. */ QVector<double> xdata, ydata; if (!data2xyvect(data, xdata, ydata)) { return NULL; } QwtPlotCurve *curve = new QwtPlotCurve(QString().fromStdString(data->get_name())); curve->setRenderHint(QwtPlotItem::RenderAntialiased); curve->setPen(QPen(_suggestColor(plotnumber))); // FIXME: offer choices curve->setLegendAttribute(QwtPlotCurve::LegendShowLine); curve->setSamples(xdata, ydata); // makes a deep copy curve->attach(this); return dynamic_cast<QWT_ABSTRACT_SERIESITEM *>(curve); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); /* Pour traduire en FR */ QString locale = QLocale::system().name().section('_', 0, 0); QTranslator translator; translator.load(QString("qt_") + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath)); app.installTranslator(&translator); /* Fin */ MaFenetre w(230,120); QwtPlot *myPlot = new QwtPlot(); myPlot->setCanvasBackground(Qt::gray); myPlot->setTitle("Répartition des pixels en rouge"); myPlot->setFixedHeight(600); myPlot->setFixedWidth(800); myPlot->setAxisScale( QwtPlot::yLeft, 0, 10000 ); //Scale the y-axis myPlot->setAxisScale(QwtPlot::xBottom,0,255); //Scale the x-axis myPlot->show(); QPolygonF points; QwtPlotCurve *courbe = new QwtPlotCurve("Rouge"); courbe->setPen(Qt::red, 2); points.append(QPointF(0.0,0.0)); points.append(QPointF(0.0,5000.0)); points.append(QPointF(50.0,5000.0)); points.append(QPointF(50.0,0.0)); courbe->setSamples(points); courbe->attach(myPlot); return app.exec(); }
void PfPvPlot::refreshZoneItems() { // clear out any zone curves which are presently defined if (zoneCurves.size()) { QListIterator<QwtPlotCurve *> i(zoneCurves); while (i.hasNext()) { QwtPlotCurve *curve = i.next(); curve->detach(); //delete curve; } } zoneCurves.clear(); // delete any existing power zone labels if (zoneLabels.size()) { QListIterator<PfPvPlotZoneLabel *> i(zoneLabels); while (i.hasNext()) { PfPvPlotZoneLabel *label = i.next(); label->detach(); delete label; } } zoneLabels.clear(); // set zones from ride or athlete and date of // first item in the compare set const Zones *zones; int zone_range = -1; // comparing does zones for items selected not current ride if (context->isCompareIntervals) { zones = context->athlete->zones(); // no athlete zones anyway! if (!zones) return; // use first compare interval date if (context->compareIntervals.count()) { zone_range = zones->whichRange(context->compareIntervals[0].data->startTime().date()); } // still not set if (zone_range == -1) { zone_range = zones->whichRange(QDate::currentDate()); } } else if (rideItem) { zones = rideItem->zones; zone_range = rideItem->zoneRange(); } else { return; // null ride and not compare etc } if (zone_range >= 0) { setCP(zones->getCP(zone_range)); // populate the zone curves QList <int> zone_power = zones->getZoneLows(zone_range); QList <QString> zone_name = zones->getZoneNames(zone_range); int num_zones = zone_power.size(); if (zone_name.size() != num_zones) return; if (num_zones > 0) { QPen *pen = new QPen(); pen->setStyle(Qt::NoPen); QwtArray<double> yvalues; // generate x values for (int z = 0; z < num_zones; z ++) { QwtPlotCurve *curve = new QwtPlotCurve(zone_name[z]); curve->setPen(*pen); QColor brush_color = zoneColor(z, num_zones); brush_color.setHsv(brush_color.hue(), brush_color.saturation() / 4, brush_color.value()); curve->setBrush(brush_color); // fill below the line curve->setZ(1 - 1e-6 * zone_power[z]); // generate data for curve if (z < num_zones - 1) { QwtArray <double> contour_yvalues; int watts = zone_power[z + 1]; int dwatts = (double) watts; for (int i = 0; i < contour_xvalues.size(); i ++) { contour_yvalues.append( (1e6 * contour_xvalues[i] < watts) ? 1e6 : dwatts / contour_xvalues[i]); } curve->setSamples(contour_xvalues, contour_yvalues); } else { // top zone has a curve at "infinite" power QwtArray <double> contour_x; QwtArray <double> contour_y; contour_x.append(contour_xvalues[0]); contour_x.append(contour_xvalues[contour_xvalues.size() - 1]); contour_y.append(1e6); contour_y.append(1e6); curve->setSamples(contour_x, contour_y); } curve->setVisible(shade_zones); curve->attach(this); zoneCurves.append(curve); } delete pen; // generate labels for existing zones for (int z = 0; z < num_zones; z ++) { PfPvPlotZoneLabel *label = new PfPvPlotZoneLabel(this, z); label->setVisible(shade_zones); label->attach(this); zoneLabels.append(label); } } } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void StatsGenMDFWidget::updateMDFPlot(QVector<float>& odf) { int err = 0; int size = 100000; // These are the input vectors QVector<float> angles; QVector<float> axes; QVector<float> weights; angles = m_MDFTableModel->getData(SGMDFTableModel::Angle); weights = m_MDFTableModel->getData(SGMDFTableModel::Weight); axes = m_MDFTableModel->getData(SGMDFTableModel::Axis); // These are the output vectors QVector<float> x; QVector<float> y; if ( Ebsd::CrystalStructure::Cubic_High == m_CrystalStructure ) { // Allocate a new vector to hold the mdf data QVector<float> mdf(CubicOps::k_MdfSize); // Calculate the MDF Data using the ODF data and the rows from the MDF Table model Texture::CalculateMDFData<float, CubicOps>(angles.data(), axes.data(), weights.data(), odf.data(), mdf.data(), static_cast<size_t>(angles.size())); // Now generate the actual XY point data that gets plotted. int npoints = 13; x.resize(npoints); y.resize(npoints); err = StatsGen::GenCubicMDFPlotData(mdf.data(), x.data(), y.data(), npoints, size); if (err < 0) { return; } } else if ( Ebsd::CrystalStructure::Hexagonal_High == m_CrystalStructure ) { // Allocate a new vector to hold the mdf data QVector<float> mdf(HexagonalOps::k_MdfSize); // Calculate the MDF Data using the ODF data and the rows from the MDF Table model Texture::CalculateMDFData<float, HexagonalOps>(angles.data(), axes.data(), weights.data(), odf.data(), mdf.data(), static_cast<size_t>(angles.size())); // Now generate the actual XY point data that gets plotted. int npoints = 20; x.resize(npoints); y.resize(npoints); err = StatsGen::GenHexMDFPlotData(mdf.data(), x.data(), y.data(), npoints, size); if (err < 0) { return; } } QwtArray<double> xD(static_cast<int>(x.size())); QwtArray<double> yD(static_cast<int>(x.size())); for (qint32 i = 0; i < x.size(); ++i) { xD[i] = static_cast<double>(x.at(i)); yD[i] = static_cast<double>(y.at(i)); } // This will actually plot the XY data in the Qwt plot widget QwtPlotCurve* curve = m_PlotCurve; #if QWT_VERSION >= 0x060000 curve->setSamples(xD, yD); #else curve->setData(xD, yD); #endif QColor color = QColor("DodgerBlue"); curve->setPen(color, 2); curve->setRenderHint( QwtPlotItem::RenderAntialiased, true ); curve->setStyle(QwtPlotCurve::Lines); QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::white ), QPen( color, 2 ), QSize( 8, 8 ) ); curve->setSymbol( symbol ); curve->attach(m_MDFPlot); m_MDFPlot->replot(); }
void setData(QVector<double> &xData, QVector<double> &yData) { workoutCurve->setSamples(xData, yData); }
int main( int argc, char **argv ) { QApplication a( argc, argv ); QwtPlot plot; plot.setTitle( "Plot Demo" ); plot.setCanvasBackground( Qt::white ); plot.setAxisScale( QwtPlot::xBottom, -1.0, 6.0 ); QwtLegend *legend = new QwtLegend(); legend->setDefaultItemMode( QwtLegendData::Checkable ); plot.insertLegend( legend ); for ( int i = 0; i < 4; i++ ) { QwtPlotCurve *curve = new QwtPlotCurve(); curve->setRenderHint( QwtPlotItem::RenderAntialiased, true ); curve->setPen( Qt::blue ); QBrush brush; QwtSymbol::Style style = QwtSymbol::NoSymbol; QString title; if ( i == 0 ) { brush = Qt::magenta; style = QwtSymbol::Path; title = "Path"; } else if ( i == 2 ) { brush = Qt::red; style = QwtSymbol::Graphic; title = "Graphic"; } else if ( i == 1 ) { brush = Qt::yellow; style = QwtSymbol::SvgDocument; title = "Svg"; } else if ( i == 3 ) { brush = Qt::cyan; style = QwtSymbol::Pixmap; title = "Pixmap"; } MySymbol *symbol = new MySymbol( style, brush ); curve->setSymbol( symbol ); curve->setTitle( title ); curve->setLegendAttribute( QwtPlotCurve::LegendShowSymbol, true ); curve->setLegendIconSize( QSize( 15, 18 ) ); QPolygonF points; points << QPointF( 0.0, 4.4 ) << QPointF( 1.0, 3.0 ) << QPointF( 2.0, 4.5 ) << QPointF( 3.0, 6.8 ) << QPointF( 4.0, 7.9 ) << QPointF( 5.0, 7.1 ); points.translate( 0.0, i * 2.0 ); curve->setSamples( points ); curve->attach( &plot ); } plot.resize( 600, 400 ); plot.show(); return a.exec(); }
// plot the all curve, with shading according to the shade mode void CpintPlot::plot_allCurve(CpintPlot *thisPlot, int n_values, const double *power_values) { clear_CP_Curves(); QVector<double> energyBests(n_values); QVector<double> time_values(n_values); // generate an array of time values for (int t = 0; t < n_values; t++) { time_values[t] = (t + 1) / 60.0; energyBests[t] = power_values[t] * time_values[t] * 60.0 / 1000.0; } // lets work out how we are shading it switch(shadeMode) { case 0 : // not shading!! break; case 1 : // value for current date // or average for date range if a range shadingCP = dateCP; break; default: case 2 : // derived value shadingCP = cp; break; } // generate zones from shading CP value if (shadingCP > 0) { QList <int> power_zone; int n_zones = zones->lowsFromCP(&power_zone, (int) int(shadingCP)); int high = n_values - 1; int zone = 0; while (zone < n_zones && high > 0) { int low = high - 1; int nextZone = zone + 1; if (nextZone >= power_zone.size()) low = 0; else { while ((low > 0) && (power_values[low] < power_zone[nextZone])) --low; } QColor color = zoneColor(zone, n_zones); QString name = zones->getDefaultZoneName(zone); QwtPlotCurve *curve = new QwtPlotCurve(name); if (appsettings->value(this, GC_ANTIALIAS, false).toBool() == true) curve->setRenderHint(QwtPlotItem::RenderAntialiased); QPen pen(color.darker(200)); pen.setWidth(2.0); curve->setPen(pen); curve->attach(thisPlot); // use a linear gradient if (shadeMode && shadingCP) { // 0 value means no shading please - and only if proper value for shadingCP color.setAlpha(64); QColor color1 = color.darker(); QLinearGradient linearGradient(0, 0, 0, height()); linearGradient.setColorAt(0.0, color); linearGradient.setColorAt(1.0, color1); linearGradient.setSpread(QGradient::PadSpread); curve->setBrush(linearGradient); // fill below the line } if (series == RideFile::none) { // this is Energy mode curve->setSamples(time_values.data() + low, energyBests.data() + low, high - low + 1); } else { curve->setSamples(time_values.data() + low, power_values + low, high - low + 1); } allCurves.append(curve); if (shadeMode && (series != RideFile::none || energyBests[high] > 100.0)) { QwtText text(name); text.setFont(QFont("Helvetica", 20, QFont::Bold)); color.setAlpha(255); text.setColor(color); QwtPlotMarker *label_mark = new QwtPlotMarker(); // place the text in the geometric mean in time, at a decent power double x, y; if (series == RideFile::none) { x = (time_values[low] + time_values[high]) / 2; y = (energyBests[low] + energyBests[high]) / 5; } else { x = sqrt(time_values[low] * time_values[high]); y = (power_values[low] + power_values[high]) / 5; } label_mark->setValue(x, y); label_mark->setLabel(text); label_mark->attach(thisPlot); allZoneLabels.append(label_mark); } high = low; ++zone; } } // no zones available: just plot the curve without zones else { QwtPlotCurve *curve = new QwtPlotCurve(tr("maximal power")); if (appsettings->value(this, GC_ANTIALIAS, false).toBool() == true) curve->setRenderHint(QwtPlotItem::RenderAntialiased); QPen pen(GColor(CCP)); pen.setWidth(appsettings->value(this, GC_LINEWIDTH, 2.0).toDouble()); curve->setPen(pen); QColor brush_color = GColor(CCP); brush_color.setAlpha(200); //curve->setBrush(QBrush::None); // brush fills below the line if (series == RideFile::none) curve->setSamples(time_values.data(), energyBests.data(), n_values); else curve->setSamples(time_values.data(), power_values, n_values); curve->attach(thisPlot); allCurves.append(curve); } // Energy mode is really only interesting in the range where energy is // linear in interval duration--up to about 1 hour. double xmax = (series == RideFile::none) ? 60.0 : time_values[n_values - 1]; QwtScaleDiv div((series == RideFile::vam ? (double) 4.993: (double) 0.017), (double)xmax); if (series == RideFile::none) div.setTicks(QwtScaleDiv::MajorTick, LogTimeScaleDraw::ticksEnergy); else div.setTicks(QwtScaleDiv::MajorTick, LogTimeScaleDraw::ticks); thisPlot->setAxisScaleDiv(QwtPlot::xBottom, div); double ymax; if (series == RideFile::none) { int i = std::lower_bound(time_values.begin(), time_values.end(), 60.0) - time_values.begin(); ymax = 10 * ceil(energyBests[i] / 10); } else { ymax = 100 * ceil(power_values[0] / 100); if (ymax == 100) ymax = 5 * ceil(power_values[0] / 5); } thisPlot->setAxisScale(thisPlot->yLeft, 0, ymax); }
void QcepImageSliceGraphController::updateDisplay() { m_Window -> clearPlot(); int curveNumber = 0; QcepImageDataBase* data = qobject_cast<QcepImageDataBase*>(m_Object.data()); if (data) { int mode = m_Window -> currentGraphMode(); int nRows = data->get_Height(); int nCols = data->get_Width(); if (mode == QcepDataObjectGraphWindow::HorizontalSlice) { int start = m_Window->get_SliceHStart(); int summed = m_Window->get_SliceHSummed(); int skipped = m_Window->get_SliceHSkipped(); int repeats = m_Window->get_SliceHRepeats(); if (summed < 1) summed = 1; if (skipped < 0) skipped = 0; if (repeats < 1) repeats = 1; for (int rpt = 0; rpt<repeats; rpt++) { QVector<double> x,y; for (int col=0; col<nCols; col++) { double s=0; int n=0; for (int sum=0; sum<summed; sum++) { int row=start+rpt*(summed+skipped)+sum; if (row < nRows) { s += data->getImageData(col, row); n += 1; } } if (n > 0) { x.append(col); y.append(s/n); } } if (x.count() > 0) { int st = start+rpt*(summed+skipped); int en = st+summed-1; if (en >= nRows) { en = nRows-1; } QwtPlotCurve *curve = NULL; if (st == en) { curve = new QwtPlotCurve(tr("row %1").arg(st)); } else { curve = new QwtPlotCurve(tr("rows %1 to %2").arg(st).arg(en)); } curve->setSamples(x, y); m_Window->m_ImagePlot->setPlotCurveStyle(curveNumber++, curve); m_Window->appendCurve(curve); } } } else if (mode == QcepDataObjectGraphWindow::VerticalSlice) { int start = m_Window->get_SliceVStart(); int summed = m_Window->get_SliceVSummed(); int skipped = m_Window->get_SliceVSkipped(); int repeats = m_Window->get_SliceVRepeats(); if (summed < 1) summed = 1; if (skipped < 0) skipped = 0; if (repeats < 1) repeats = 1; for (int rpt = 0; rpt<repeats; rpt++) { QVector<double> x,y; for (int row=0; row<nRows; row++) { double s=0; int n=0; for (int sum=0; sum<summed; sum++) { int col=start+rpt*(summed+skipped)+sum; if (col < nCols) { s += data->getImageData(col, row); n += 1; } } if (n > 0) { x.append(row); y.append(s/n); } } if (x.count() > 0) { int st = start+rpt*(summed+skipped); int en = st+summed-1; if (en >= nCols) { en = nCols-1; } QwtPlotCurve *curve = NULL; if (st == en) { curve = new QwtPlotCurve(tr("col %1").arg(st)); } else { curve = new QwtPlotCurve(tr("cols %1 to %2").arg(st).arg(en)); } curve->setSamples(x, y); m_Window->m_ImagePlot->setPlotCurveStyle(curveNumber++, curve); m_Window->appendCurve(curve); } } } } m_Window -> m_ImagePlot -> replot(); QcepDataObjectGraphController::updateDisplay(); }