Results 1 to 14 of 14

Thread: problem in plotting QwtMatrixRasterData using QwtPlotSpectrogram

  1. #1
    Join Date
    Jul 2011
    Posts
    12
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default problem in plotting QwtMatrixRasterData using QwtPlotSpectrogram

    Hi;
    I am new bie to qt and qwt. i was trying to understand rasterview example ,in this example values are plotted on XBottom and y left axis, but in my application I have to plot same type data on xTop and y left axis .(It means orientation of plot may change)
    while going thru QWT ,i understood that by default QwtMatrixRasterData is plotted on xBottom and yleft axis ,CAn any body suggest how to plot values on XTop and yleft axis?

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

    Default Re: problem in plotting QwtMatrixRasterData using QwtPlotSpectrogram

    Qt Code:
    1. spectrogram->setXAxis( QwtPlot::XTop );
    To copy to clipboard, switch view to plain text mode 
    Uwe

  3. #3
    Join Date
    Jul 2011
    Posts
    12
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem in plotting QwtMatrixRasterData using QwtPlotSpectrogram

    expected_op.jpg
    Hi ,
    I tried your tip but i didnt get expected result(attached with this reply) code is as below:

    #include "plot.h"
    #include <qwt_color_map.h>
    #include <qwt_plot_spectrogram.h>
    #include <qwt_plot_layout.h>
    #include <qwt_matrix_raster_data.h>
    #include <qwt_scale_widget.h>
    #include <qwt_plot_magnifier.h>
    #include <qwt_plot_panner.h>
    #include <qwt_plot_renderer.h>
    #include <qwt_plot_grid.h>
    #include <qfiledialog.h>
    #include <qimagewriter.h>

    class RasterData: public QwtMatrixRasterData
    {
    public:
    RasterData()
    {
    const double matrix[] =
    {
    1.0000,0.0443,0.0098,0.0740,0.0030,0.0122,0.0001,
    0.0443,1.0000,0.0122,0.0354,0.0013,0.0024,0.0001,
    0.0098,0.0122,1.0000,0.1146,0.0520,0.0054,0.0068,
    0.0740,0.0354,0.1146,1.0000,0.0131,0.0589,0.0011,
    0.0030,0.0013,0.0520,0.0131,1.0000,0.0105,0.0169,
    0.0122,0.0024,0.005,0.0589,0.0105,1.0000,0.0187,
    0.0001,0.0001,0.0068,0.0011,0.0169,0.0187,1.0000,

    };

    QVector<double> values;
    for ( uint i = 0; i < sizeof(matrix) / sizeof(double); i++ )
    values += matrix[i];

    // const int numColumns = 4;
    const int numColumns = 7;
    setValueMatrix(values, numColumns);

    //setInterval( Qt::XAxis,
    // QwtInterval( -0.5, 3.5, QwtInterval::ExcludeMaximum ) );
    setInterval( Qt::XAxis,
    QwtInterval( 0.5, 7.5, QwtInterval::ExcludeMaximum ) );
    // setInterval( Qt::YAxis,
    // QwtInterval( -0.5, 3.5, QwtInterval::ExcludeMaximum ) );
    setInterval( Qt::YAxis,
    QwtInterval( 0.5, 7.5, QwtInterval::ExcludeMaximum ) );
    //setInterval( Qt::ZAxis, QwtInterval(1.0, 6.0) );
    setInterval( Qt::ZAxis, QwtInterval(0.0, 1.0) );
    }
    };

    class ColorMap: public QwtLinearColorMap
    {
    public:
    ColorMap():
    QwtLinearColorMap(Qt::darkBlue, Qt::darkRed)
    {
    addColorStop(0.2, Qt::blue);
    addColorStop(0.4, Qt::cyan);
    addColorStop(0.6, Qt::yellow);
    addColorStop(0.8, Qt::red);
    /* addColorStop(0.1, Qt::blue);
    addColorStop(0.2, Qt::blue);
    addColorStop(0.3, Qt::blue);
    addColorStop(0.4, Qt::cyan);
    addColorStop(0.6, Qt::yellow);
    addColorStop(0.8, Qt::red);*/
    }
    };

    Plot::Plot(QWidget *parent):
    QwtPlot(parent)
    {
    #if 0
    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->setPen(QPen(Qt:otLine));
    grid->attach(this);
    #endif

    d_spectrogram = new QwtPlotSpectrogram();
    d_spectrogram->setRenderThreadCount(0); // use system specific thread count

    d_spectrogram->setColorMap( new ColorMap() );

    d_spectrogram->setData(new RasterData());
    d_spectrogram->attach(this);

    const QwtInterval zInterval = d_spectrogram->data()->interval( Qt::ZAxis );
    // A color bar on the right axis
    QwtScaleWidget *rightAxis = axisWidget(QwtPlot::yRight);
    rightAxis->setColorBarEnabled(true);
    rightAxis->setColorBarWidth(40);
    rightAxis->setColorMap(zInterval, new ColorMap() );

    setAxisScale(QwtPlot::yRight,zInterval.minValue(), zInterval.maxValue(),0.1 );
    enableAxis(QwtPlot::yRight);

    plotLayout()->setAlignCanvasToScales(true);

    // setAxisScale(QwtPlot::xBottom, 0.0, 3.0);
    setAxisScale(QwtPlot::xTop, 1.0, 7.0);
    //setAxisMaxMinor(QwtPlot::xBottom, 0);
    //setAxisMaxMinor(QwtPlot::xBottom, 0);
    setAxisMaxMinor(QwtPlot::xTop, 0);
    setAxisScale(QwtPlot::yLeft, 1.0, 7.0);
    setAxisMaxMinor(QwtPlot::yLeft, 0);

    // QwtPlotMagnifier *magnifier = new QwtPlotMagnifier( canvas() );
    // magnifier->setAxisEnabled( QwtPlot::yRight, false);

    QwtPlotPanner *panner = new QwtPlotPanner( canvas() );
    panner->setAxisEnabled( QwtPlot::yRight, false);
    }

    void Plot::exportPlot()
    {
    QString fileName = "rasterview.pdf";

    #ifndef QT_NO_FILEDIALOG
    const QList<QByteArray> imageFormats =
    QImageWriter::supportedImageFormats();

    QStringList filter;
    filter += "PDF Documents (*.pdf)";
    #ifndef QWT_NO_SVG
    filter += "SVG Documents (*.svg)";
    #endif
    filter += "Postscript Documents (*.ps)";

    if ( imageFormats.size() > 0 )
    {
    QString imageFilter("Images (");
    for ( int i = 0; i < imageFormats.size(); i++ )
    {
    if ( i > 0 )
    imageFilter += " ";
    imageFilter += "*.";
    imageFilter += imageFormats[i];
    }
    imageFilter += ")";

    filter += imageFilter;
    }

    fileName = QFileDialog::getSaveFileName(
    this, "Export File Name", fileName,
    filter.join(";;"), NULL, QFileDialog:ontConfirmOverwrite);
    #endif
    if ( !fileName.isEmpty() )
    {
    QwtPlotRenderer renderer;
    renderer.renderDocument(this, fileName, QSizeF(300, 200), 85);
    }
    }

    void Plot::setResampleMode(int mode)
    {
    RasterData *data = (RasterData *)d_spectrogram->data();
    data->setResampleMode( (QwtMatrixRasterData::ResampleMode) mode);

    replot();
    }


    Please let me know where i am wrong and how to plot this graph

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: problem in plotting QwtMatrixRasterData using QwtPlotSpectrogram

    Beside, that the screenshot is so small, that I can hardly see the scales: is it what you want to have or what you get ? And if it is not what you want to have- what exactly is wrong with it ?

    Uwe

  5. #5
    Join Date
    Jul 2011
    Posts
    12
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem in plotting QwtMatrixRasterData using QwtPlotSpectrogram

    Hi Uwe,
    The attached image is expected result and scale is (xTop :1 to 7
    YLeft: 1 to 7 (from up to down).

    In my actual out put i am getting y axis divison as 1 to 7(from down to up ) and output images(red squares) as diagonally right up to left down( which should be diagonally left up to left down).
    Can u pls see the code what modification is required for same values as given in code?
    Thanks in advance
    Last edited by johnMick; 25th July 2011 at 12:07.

  6. #6
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: problem in plotting QwtMatrixRasterData using QwtPlotSpectrogram

    If all you want is to invert the y axis:

    Qt Code:
    1. //setAxisScale(QwtPlot::yLeft, 1.0, 7.0);
    2. setAxisScale(QwtPlot::yLeft, 7.0, 1.0);
    To copy to clipboard, switch view to plain text mode 
    In case of using autoscaling this can be done with setting the QwtScaleEngine::Inverted attribute.

    Uwe

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

    johnMick (25th July 2011)

  8. #7
    Join Date
    Jul 2011
    Posts
    12
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem in plotting QwtMatrixRasterData using QwtPlotSpectrogram

    I also wanted that my red squares will start from 0.5 and end with 1.5 ? what values should i set in setInterval method?

  9. #8
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: problem in plotting QwtMatrixRasterData using QwtPlotSpectrogram

    Quote Originally Posted by johnMick View Post
    I also wanted that my red squares will start from 0.5 and end with 1.5 ?
    That's what they do, but you are setting the scales, so that half of the first square is cut off.

    I guess this is your code:

    Qt Code:
    1. #if 0
    2. setAxisScale( QwtPlot::xTop, 1.0, 7.0 );
    3. setAxisScale( QwtPlot::yLeft, 7.0, 1.0 );
    4. #else
    5. for ( int i = 0; i < QwtPlot::axisCnt; i++ )
    6. axisScaleEngine( i )->setAttribute( QwtScaleEngine::Floating, true );
    7. axisScaleEngine( yLeft )->setAttribute( QwtScaleEngine::Inverted, true );
    8. #endif
    To copy to clipboard, switch view to plain text mode 
    Uwe

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

    johnMick (26th July 2011)

  11. #9
    Join Date
    Jul 2011
    Posts
    12
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem in plotting QwtMatrixRasterData using QwtPlotSpectrogram

    Hi,
    I have one more doubt , in my output red image(color zone) is coming as rectangle but i want should be display as square
    is it any way that i can set color zone as square?

  12. #10
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: problem in plotting QwtMatrixRasterData using QwtPlotSpectrogram

    A spectrogram or any raster data object has no color zones, rectangles or squares !

    I guess what you want to have is a plot with a fixed aspect ratio ( see qwt_plot_rescaler ).

    Uwe

  13. #11
    Join Date
    Jul 2011
    Posts
    12
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem in plotting QwtMatrixRasterData using QwtPlotSpectrogram

    But in thiscase, i have given 7*7 matrix value to QWTMatrixRaster Data, hence total row and column should be 7
    hence 7 squares(red squares) should be displayed
    But in output it is showing only 6 red squares it means row and column are 6 .


    Can u pls explain why its happening? Is there any problem in coding?


    Added after 53 minutes:


    I tried to set set aspect ratio by using below code

    QwtPlotRescaler *ptr = new QwtPlotRescaler(this->canvas(),QwtPlot::xTop);
    ptr->setAspectRatio(QwtPlot::xTop,0.0);


    where this is pointer to QWTPlot but when i used this lines ,all the plot gone and in output only x and y axis is displayed
    what was the problem , how to set aspect ratio?
    Last edited by johnMick; 26th July 2011 at 11:18.

  14. #12
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: problem in plotting QwtMatrixRasterData using QwtPlotSpectrogram

    Quote Originally Posted by johnMick View Post
    But in thiscase, i have given 7*7 matrix value to QWTMatrixRaster Data, hence total row and column should be 7
    hence 7 squares(red squares) should be displayed
    But in output it is showing only 6 red squares it means row and column are 6 .
    On my box I can see 7 rows and columns with your code ( with the changes I have posted ). Probably it helps to understand, that the current scales and the bounding rectangle of the plot items are different things - beside, that in case of autoscaling the scales are adjusted to the bounding rectangles.

    Quote Originally Posted by johnMick View Post
    QwtPlotRescaler *ptr = new QwtPlotRescaler(this->canvas(),QwtPlot::xTop);
    ptr->setAspectRatio(QwtPlot::xTop,0.0);
    This is what you wrote: dy = dx / 0.0;

    What do you expect to get when you have a reference of [0-7] and a aspect ratio of 0.0 ? In fact a value of 0.0 disables rescaling of the axis.

    Uwe

  15. #13
    Join Date
    Jul 2011
    Posts
    26
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem in plotting QwtMatrixRasterData using QwtPlotSpectrogram

    do I understand it right, that MatrixRasterData divides a QVector in numColoumns, when I call setValues() ?? Finally I need a Vector instead of a Matrix (2D-vector) ?

  16. #14
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: problem in plotting QwtMatrixRasterData using QwtPlotSpectrogram

    Qt offers no container for matrices - and I don't want to introduce dependencies to the Boost library only because of this. That's all.

    Uwe

Similar Threads

  1. Google map on QwtPlotSpectrogram
    By sagittager in forum Qwt
    Replies: 4
    Last Post: 15th October 2011, 15:32
  2. Problem in plotting 3D plot using QWT
    By johnMick in forum Newbie
    Replies: 1
    Last Post: 15th July 2011, 11:19
  3. Bugs in QwtMatrixRasterData?
    By alex_sh in forum Qwt
    Replies: 13
    Last Post: 23rd January 2011, 11:59
  4. Replies: 9
    Last Post: 3rd December 2009, 18:19
  5. Irregular data and QwtPlotSpectrogram
    By seveninches in forum Qwt
    Replies: 1
    Last Post: 27th January 2008, 10:52

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.