Results 1 to 2 of 2

Thread: QwtSpectogram and scaling the Axis

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

    Default QwtSpectogram and scaling the Axis

    Hi Community,

    I have the following problem:

    I want to display a preview of an AirBearing_pressureDistribution in a SpectogramPlot.

    Now what I get is a Spectogram:



    Now the xTop und yLeft scales are scaled to the Matrix ( or to the number of elements that are in the MatrixVector here 102x102)

    -> Why doesn't he go to 102 on the xTop scale, when I have 102x102 elements?

    What I want is this picture, but scaled to the Bearing length and width. What I get is this:



    How can I rescale the Plot, so he shows the first image in the length/width-rescaled plot.

    Here the code:


    Qt Code:
    1. #include "preview.h"
    2. #include <QFile>
    3.  
    4. class previewColorMap : public QwtLinearColorMap
    5. {
    6. public:
    7. previewColorMap(float pa, float pd) : QwtLinearColorMap(Qt::blue, Qt::darkRed)
    8. {
    9. addColorStop(0.05, Qt::blue);
    10. addColorStop(0.3, Qt::cyan);
    11. addColorStop(0.7, Qt::yellow);
    12. addColorStop(0.9, Qt::red);
    13. addColorStop(1, Qt::darkRed);
    14. }
    15. };
    16.  
    17. class previewMatrixData : public QwtMatrixRasterData
    18. {
    19. public:
    20. previewMatrixData(const QVector<double> &pressureVector, int Nx, int Ny, float dx, float dy, float pd)
    21. {
    22. setValueMatrix(pressureVector, Ny+2);
    23. setInterval(Qt::YAxis, QwtInterval(0, Ny+2));
    24. setInterval(Qt::XAxis, QwtInterval(0, Nx+2));
    25. setInterval(Qt::ZAxis, QwtInterval(0, pd));
    26. setResampleMode(BilinearInterpolation);
    27. }
    28. };
    29.  
    30. preview::preview(QWidget *parent) : QWidget(parent)
    31. {
    32. this->setAttribute(Qt::WA_DeleteOnClose, true);
    33.  
    34. previewPlot = new QwtPlot;
    35. previewSpectogram = new QwtPlotSpectrogram;
    36. previewSpectogram->attach(previewPlot);
    37. previewPlotLayout = new QVBoxLayout;
    38. previewPlotLayout->setAlignment(Qt::AlignCenter);
    39. previewPlotLayout->addWidget(previewPlot);
    40.  
    41.  
    42. // canvasBackground = new QBrush(Qt::white, Qt::SolidPattern);
    43. previewPlot->setCanvasBackground(QBrush(Qt::white, Qt::SolidPattern));
    44. previewPlot->setCanvasLineWidth(0);
    45. previewPlot->enableAxis(0, true);
    46. previewPlot->enableAxis(2, false);
    47. previewPlot->enableAxis(3, true);
    48. previewPlot->plotLayout()->setAlignCanvasToScales(true);
    49. previewPlot->setAxisScale(0, 10, 0);
    50. previewPlot->setAxisScale(3, 0, 10);
    51. previewPlot->axisWidget(0)->setMargin(10);
    52. previewPlot->axisWidget(3)->setMargin(10);
    53.  
    54. this->setLayout(previewPlotLayout);
    55. }
    56.  
    57. void preview::constructOrificePreview(QTableWidget *orificePos)
    58. {
    59.  
    60. ///////ALGORITHM HERE EXTRACTED FROM CODE
    61.  
    62.  
    63. qDebug() << rasterMatrix.size();
    64. qDebug() << rasterMatrix.count();
    65. qDebug() << "Nx " << Nx << "Ny " << Ny;
    66.  
    67. (Debug_output =
    68. 10404, 10404, 100, 100 )
    69.  
    70.  
    71. previewSpectogram->setColorMap(new previewColorMap(pa, pd));
    72. previewSpectogram->setData(new previewMatrixData(rasterMatrix, Nx, Ny, dx, dy, pd));
    73. previewPlot->axisWidget(QwtPlot::yRight)->setTitle(tr("Intensität"));
    74. previewPlot->axisWidget(QwtPlot::yRight)->setColorBarEnabled(true);
    75. previewPlot->axisWidget(QwtPlot::yRight)->setColorMap(QwtInterval(pa/1e6, pd/1e6), new previewColorMap(pa/1e6,pd/1e6));
    76. previewPlot->setAxisScale(QwtPlot::yRight, pa/1e6, pd/1e6);
    77. previewPlot->enableAxis(1, true);
    78.  
    79. previewPlot->setAxisScale(QwtPlot::xTop, 0.0 , x*1e3);
    80. previewPlot->setAxisMaxMinor(QwtPlot::xTop, 5);
    81. previewPlot->setAxisScale(QwtPlot::yLeft, y*1e3, 0.0);
    82. previewPlot->setAxisMaxMinor(QwtPlot::yLeft, 5);
    83.  
    84. previewPlot->replot();
    85. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: QwtSpectogram and scaling the Axis

    A plot item can be related to one x and one y axis only - the default setting is xBottom/yLeft. Guess you want to do this:

    Qt Code:
    1. previewSpectrogram->setAxes( QwtPlot::xTop, QwtPlot::yLeft );
    To copy to clipboard, switch view to plain text mode 

    Uwe

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

    revellix (26th August 2011)

Similar Threads

  1. improve the auto scaling of axis
    By 21did21 in forum Qwt
    Replies: 7
    Last Post: 7th July 2011, 20:26
  2. Replies: 3
    Last Post: 18th May 2011, 21:33
  3. Y axis not auto scaling
    By pkj in forum Qwt
    Replies: 0
    Last Post: 12th May 2011, 17:05
  4. Replies: 9
    Last Post: 3rd May 2011, 22:21
  5. Scaling Painter without scaling the coordinate sytem
    By maverick_pol in forum Qt Programming
    Replies: 4
    Last Post: 7th January 2008, 22:30

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.