oria66
19th December 2017, 14:42
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
Uwe
20th December 2017, 06:29
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
oria66
20th December 2017, 15:50
Hello everyone. Thanks to Uwe and this post https://www.developpez.net/forums/d1496128/c-cpp/bibliotheques/qt/outils/bibliotheques/qwt/utilisation-plusieurs-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, :p.
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();
}
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.