Results 1 to 3 of 3

Thread: Simple example with QwtPlot multiaxes

  1. #1
    Join Date
    Oct 2017
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Simple example with QwtPlot multiaxes

    Hi everyone!

    Recently I take a look to qwtplot multiaxes. However, I can't find any simple example, an start point to show how to integrate multiple Y axis with one X axis.

    Please, anyone can show me how to do this?

    Any help would be appreciated!

    Thanks

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,172
    Thanked 836 Times in 785 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Simple example with QwtPlot multiaxes

    Well there is no example, but there is not that much to explain as it works almost the same as the original version.
    Simply define your axes with QwtPlot::setAxesCount and then use a QwtAxisId where you were using QwtPlot::Axis.

    Uwe

  3. The following user says thank you to Uwe for this useful post:

    oria66 (20th December 2017)

  4. #3
    Join Date
    Oct 2017
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Simple example with QwtPlot multiaxes

    Hello everyone. Thanks to Uwe and this post https://www.developpez.net/forums/d1...lusieurs-axes/, I can finally do a simple example of qwtplot with multiaxes support. The problem is my qwtplot documentation refer to version 6.1.3, and don't have the new features, .

    Although basic, it can help starters in multi-axis qwt plot. This is the example:

    #include <QApplication>
    #include <qwt_plot.h>
    #include <qwt_plot_curve.h>
    #include <qwt_plot_grid.h>
    #include <qwt_symbol.h>
    #include <qwt_legend.h>
    #include <qwt_point_data.h>
    #include <qwt_plot_canvas.h>
    #include <qwt_axis_id.h>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    QwtAxisId axisY1(QwtPlot::yLeft,0);
    QwtAxisId axisY2(QwtPlot::yLeft,1);

    QwtPlot plot;
    plot.setTitle( "Plot Demo" );
    plot.setCanvasBackground( Qt::white );
    plot.setAxesCount(QwtPlot::yLeft, 2);

    plot.setAxisAutoScale(axisY1,true);
    plot.setAxisAutoScale(axisY2,true);

    plot.enableAxis(QwtPlot::xBottom,false);

    plot.setAxisVisible(axisY1,false); //Comment this to show the axis 1
    plot.setAxisVisible(axisY2,false); //Comment this to show the axis 2

    plot.insertLegend( new QwtLegend() );

    QwtPlotCanvas *canvas = new QwtPlotCanvas();
    canvas->setLineWidth( 1 );
    canvas->setFrameStyle( QFrame::Box | QFrame::Plain );

    QPalette canvasPalette( Qt::white );
    canvasPalette.setColor( QPalette::Foreground, QColor( 131, 131, 131 ) );
    canvas->setPalette( canvasPalette );

    plot.setCanvas(canvas);

    QVector<double> listX;
    QVector<double> list1y, list2y;

    for (int var = 0.1; var < 6.28; ++var) {
    listX.push_back(var);
    list1y.push_back(sin(var));
    list2y.push_back(2*cos(var));
    }

    QwtPointArrayData *data1=new QwtPointArrayData(listX,list1y);
    QwtPointArrayData *data2=new QwtPointArrayData(listX,list2y);

    QwtPlotCurve *curve1 = new QwtPlotCurve();
    QwtPlotCurve *curve2 = new QwtPlotCurve();

    curve1->setTitle( "Curve Sin(x)" );
    curve1->setPen( Qt::blue, 4 ),
    curve1->setRenderHint( QwtPlotItem::RenderAntialiased, true );
    curve1->setSamples(data1);

    curve2->setTitle( "Curve 2*cos(x)" );
    curve2->setPen( Qt::red, 4 ),
    curve2->setRenderHint( QwtPlotItem::RenderAntialiased, true );
    curve2->setSamples(data2);

    curve1->setYAxis(axisY1);
    curve2->setYAxis(axisY2);

    curve1->attach( &plot );
    curve2->attach( &plot );

    plot.replot();
    plot.resize( 600, 400 );
    plot.show();

    return a.exec();
    }

Similar Threads

  1. qwt-6.1-multiaxes and findChildren()
    By VALE61 in forum Qwt
    Replies: 1
    Last Post: 27th April 2016, 15:33
  2. Qwt with multiaxes support - bug?
    By Khaine in forum Qwt
    Replies: 0
    Last Post: 13th April 2016, 21:25
  3. Replies: 1
    Last Post: 12th April 2015, 10:16
  4. Replies: 8
    Last Post: 24th November 2010, 23:18
  5. Replies: 1
    Last Post: 30th July 2010, 07:23

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.