Results 1 to 14 of 14

Thread: problem in plotting QwtMatrixRasterData using QwtPlotSpectrogram

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    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

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

    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

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    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

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

    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 13:07.

  5. #5
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    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

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

    johnMick (25th July 2011)

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

    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?

  8. #7
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    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

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

    johnMick (26th July 2011)

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

    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?

  11. #9
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    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

Similar Threads

  1. Google map on QwtPlotSpectrogram
    By sagittager in forum Qwt
    Replies: 4
    Last Post: 15th October 2011, 16:32
  2. Problem in plotting 3D plot using QWT
    By johnMick in forum Newbie
    Replies: 1
    Last Post: 15th July 2011, 12:19
  3. Bugs in QwtMatrixRasterData?
    By alex_sh in forum Qwt
    Replies: 13
    Last Post: 23rd January 2011, 12:59
  4. Replies: 9
    Last Post: 3rd December 2009, 19:19
  5. Irregular data and QwtPlotSpectrogram
    By seveninches in forum Qwt
    Replies: 1
    Last Post: 27th January 2008, 11: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
  •  
Qt is a trademark of The Qt Company.