示例#1
0
  MyPlot( QWidget *parent=0, char *name=0 ) : QwtPlot( parent, name )
  {
    // Show a title
    setTitle( "This is an Example" );

    // Show a legend at the bottom
    setAutoLegend( true );
    setLegendPos( Qwt::Bottom );

    // Show the axes
    setAxisTitle( xBottom, "x" );
    setAxisTitle( yLeft, "y" );

    // Insert two curves and get IDs for them
    long cSin = insertCurve( "y = sin(x)" );
    long cSign = insertCurve( "y = sign(sin(x))" );

    // Calculate the data, 500 points each
    const int points = 500;
    double x[ points ];
    double sn[ points ];
    double sg[ points ];

    for( int i=0; i<points; i++ )
    {
      x[i] = (3.0*3.14/double(points))*double(i);
    
      sn[i] = 2.0*sin( x[i] );
      sg[i] = (sn[i]>0)?1:((sn[i]<0)?-1:0);
    }

    // Copy the data to the plot
    setCurveData( cSin, x, sn, points );
    setCurveData( cSign, x, sg, points );

    // Set the style of the curves
    setCurvePen( cSin, QPen( blue ) );
    setCurvePen( cSign, QPen( green, 3 ) );

    // Show the plots
    replot();
  }
示例#2
0
Plot::Plot( QWidget *parent ):
    QwtPlot( parent )
{
    setObjectName( "FriedbergPlot" );
    setTitle( "Temperature of Friedberg/Germany" );

    setAxisTitle( QwtPlot::xBottom, "2007" );
    setAxisScaleDiv( QwtPlot::xBottom, yearScaleDiv() );
    setAxisScaleDraw( QwtPlot::xBottom, new YearScaleDraw() );

    setAxisTitle( QwtPlot::yLeft,
        QString( "Temperature [%1C]" ).arg( QChar( 0x00B0 ) ) );

    // grid
    QwtPlotGrid *grid = new Grid;
    grid->attach( this );

    insertLegend( new QwtLegend(), QwtPlot::RightLegend );

    const int numDays = 365;
    QVector<QPointF> averageData( numDays );
    QVector<QwtIntervalSample> rangeData( numDays );

    for ( int i = 0; i < numDays; i++ )
    {
        const Temperature &t = friedberg2007[i];
        averageData[i] = QPointF( double( i ), t.averageValue );
        rangeData[i] = QwtIntervalSample( double( i ),
            QwtInterval( t.minValue, t.maxValue ) );
    }

    insertCurve( "Average", averageData, Qt::black );
    insertErrorBars( "Range", rangeData, Qt::blue );

    // LeftButton for the zooming
    // MidButton for the panning
    // RightButton: zoom out by 1
    // Ctrl+RighButton: zoom out to full size

    QwtPlotZoomer* zoomer = new QwtPlotZoomer( canvas() );
    zoomer->setRubberBandPen( QColor( Qt::black ) );
    zoomer->setTrackerPen( QColor( Qt::black ) );
    zoomer->setMousePattern( QwtEventPattern::MouseSelect2,
        Qt::RightButton, Qt::ControlModifier );
    zoomer->setMousePattern( QwtEventPattern::MouseSelect3,
        Qt::RightButton );

    QwtPlotPanner *panner = new QwtPlotPanner( canvas() );
    panner->setMouseButton( Qt::MidButton );

    canvas()->setPalette( Qt::darkGray );
    canvas()->setBorderRadius( 10 );
}
示例#3
0
文件: plot.cpp 项目: albore/pandora
void Plot::insertCurve(int axis, double base)
{
    Qt::Orientation o;
    if ( axis == yLeft || axis == yRight )
        o = Qt::Horizontal;
    else
        o = Qt::Vertical;
    
    QRgb rgb = (uint)rand();
    insertCurve(o, QColor(rgb), base);
    replot();
}
示例#4
0
Plot::Plot( QWidget *parent ):
    QwtPlot( parent)
{
    setPalette( Qt::black );

    // we want to have the axis scales like a frame around the
    // canvas
    plotLayout()->setAlignCanvasToScales( true );
    for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
        axisWidget( axis )->setMargin( 0 );

    QwtPlotCanvas *canvas = new QwtPlotCanvas();
    canvas->setAutoFillBackground( false );
    canvas->setFrameStyle( QFrame::NoFrame );
    setCanvas( canvas );

    setAxisScale( QwtPlot::yLeft, 0.0, 10.0 );

    // a title
    QwtText title( "Picker Demo" );
    title.setColor( Qt::white );
    title.setRenderFlags( Qt::AlignHCenter | Qt::AlignTop );

    QFont font;
    font.setBold( true );
    title.setFont( font );

    QwtPlotTextLabel *titleItem = new QwtPlotTextLabel();
    titleItem->setText( title );
    titleItem->attach( this );

#if 1
    // section

    //QColor c( "PaleVioletRed" );

    QwtPlotZoneItem* zone = new QwtPlotZoneItem();
    zone->setPen( Qt::darkGray );
    zone->setBrush( QColor( "#834358" ) );
    zone->setOrientation( Qt::Horizontal );
    zone->setInterval( 3.8, 5.7 );
    zone->attach( this );

#else
    // grid

    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->setMajorPen( Qt::white, 0, Qt::DotLine );
    grid->setMinorPen( Qt::gray, 0 , Qt::DotLine );
    grid->attach( this );
#endif

    // curves

    QPolygonF points1;
    points1 << QPointF( 0.2, 4.4 ) << QPointF( 1.2, 3.0 )
            << QPointF( 2.7, 4.5 ) << QPointF( 3.5, 6.8 )
            << QPointF( 4.7, 7.9 ) << QPointF( 5.8, 7.1 );

    insertCurve( "Curve 1", "DarkOrange", points1 );

    QPolygonF points2;
    points2 << QPointF( 0.4, 8.7 ) << QPointF( 1.4, 7.8 )
            << QPointF( 2.3, 5.5 ) << QPointF( 3.3, 4.1 )
            << QPointF( 4.4, 5.2 ) << QPointF( 5.6, 5.7 );

    insertCurve( "Curve 2", "DodgerBlue", points2 );

    CurveTracker* tracker = new CurveTracker( this->canvas() );

    // for the demo we want the tracker to be active without
    // having to click on the canvas
    tracker->setStateMachine( new QwtPickerTrackerMachine() );
    tracker->setRubberBandPen( QPen( "MediumOrchid" ) );
}
示例#5
0
文件: plot.cpp 项目: albore/pandora
Plot::Plot(QWidget *parent):
    QwtPlot(parent)
{
    setTitle("Interactive Plot");

    setCanvasColor(Qt::darkCyan);

    QwtPlotGrid *grid = new QwtPlotGrid;
    grid->setMajPen(QPen(Qt::white, 0, Qt::DotLine));
    grid->attach(this);

    // axes

    setAxisScale(QwtPlot::xBottom, 0.0, 100.0);
    setAxisScale(QwtPlot::yLeft, 0.0, 100.0);

    // Avoid jumping when label with 3 digits
    // appear/disappear when scrolling vertically

    QwtScaleDraw *sd = axisScaleDraw(QwtPlot::yLeft);
    sd->setMinimumExtent( sd->extent(axisWidget(QwtPlot::yLeft)->font()));

    plotLayout()->setAlignCanvasToScales(true);

    insertCurve(Qt::Vertical, Qt::blue, 30.0);
    insertCurve(Qt::Vertical, Qt::magenta, 70.0);
    insertCurve(Qt::Horizontal, Qt::yellow, 30.0);
    insertCurve(Qt::Horizontal, Qt::white, 70.0);

    replot();

    // ------------------------------------
    // We add a color bar to the left axis
    // ------------------------------------

    QwtScaleWidget *scaleWidget = (QwtScaleWidget *)axisWidget(yLeft);
    scaleWidget->setMargin(10); // area for the color bar
    d_colorBar = new ColorBar(Qt::Vertical, scaleWidget);
    d_colorBar->setRange(Qt::red, Qt::darkBlue);
    d_colorBar->setFocusPolicy(Qt::TabFocus);

    connect(d_colorBar, SIGNAL(selected(const QColor &)),
        SLOT(setCanvasColor(const QColor &)));

    // we need the resize events, to lay out the color bar
    scaleWidget->installEventFilter(this); 

    // ------------------------------------
    // We add a wheel to the canvas
    // ------------------------------------

    d_wheel = new QwtWheel(canvas());
    d_wheel->setOrientation(Qt::Vertical);
    d_wheel->setRange(-100, 100);
    d_wheel->setValue(0.0);
    d_wheel->setMass(0.2);
    d_wheel->setTotalAngle(4 * 360.0);

    connect(d_wheel, SIGNAL(valueChanged(double)),
        SLOT(scrollLeftAxis(double)));

    // we need the resize events, to lay out the wheel
    canvas()->installEventFilter(this);

    d_colorBar->setWhatsThis(
        "Selecting a color will change the background of the plot.");
    scaleWidget->setWhatsThis(
        "Selecting a value at the scale will insert a new curve.");
    d_wheel->setWhatsThis(
        "With the wheel you can move the visible area.");
    axisWidget(xBottom)->setWhatsThis(
        "Selecting a value at the scale will insert a new curve.");
}