PDA

View Full Version : QwtSpectogram and scaling the Axis



revellix
24th August 2011, 16:00
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:

http://i54.tinypic.com/2w65p9k.png

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:

http://i52.tinypic.com/2z6yse8.png

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

Here the code:




#include "preview.h"
#include <QFile>

class previewColorMap : public QwtLinearColorMap
{
public:
previewColorMap(float pa, float pd) : QwtLinearColorMap(Qt::blue, Qt::darkRed)
{
addColorStop(0.05, Qt::blue);
addColorStop(0.3, Qt::cyan);
addColorStop(0.7, Qt::yellow);
addColorStop(0.9, Qt::red);
addColorStop(1, Qt::darkRed);
}
};

class previewMatrixData : public QwtMatrixRasterData
{
public:
previewMatrixData(const QVector<double> &pressureVector, int Nx, int Ny, float dx, float dy, float pd)
{
setValueMatrix(pressureVector, Ny+2);
setInterval(Qt::YAxis, QwtInterval(0, Ny+2));
setInterval(Qt::XAxis, QwtInterval(0, Nx+2));
setInterval(Qt::ZAxis, QwtInterval(0, pd));
setResampleMode(BilinearInterpolation);
}
};

preview::preview(QWidget *parent) : QWidget(parent)
{
this->setAttribute(Qt::WA_DeleteOnClose, true);

previewPlot = new QwtPlot;
previewSpectogram = new QwtPlotSpectrogram;
previewSpectogram->attach(previewPlot);
previewPlotLayout = new QVBoxLayout;
previewPlotLayout->setAlignment(Qt::AlignCenter);
previewPlotLayout->addWidget(previewPlot);


// canvasBackground = new QBrush(Qt::white, Qt::SolidPattern);
previewPlot->setCanvasBackground(QBrush(Qt::white, Qt::SolidPattern));
previewPlot->setCanvasLineWidth(0);
previewPlot->enableAxis(0, true);
previewPlot->enableAxis(2, false);
previewPlot->enableAxis(3, true);
previewPlot->plotLayout()->setAlignCanvasToScales(true);
previewPlot->setAxisScale(0, 10, 0);
previewPlot->setAxisScale(3, 0, 10);
previewPlot->axisWidget(0)->setMargin(10);
previewPlot->axisWidget(3)->setMargin(10);

this->setLayout(previewPlotLayout);
}

void preview::constructOrificePreview(QTableWidget *orificePos)
{

///////ALGORITHM HERE EXTRACTED FROM CODE


qDebug() << rasterMatrix.size();
qDebug() << rasterMatrix.count();
qDebug() << "Nx " << Nx << "Ny " << Ny;

(Debug_output =
10404, 10404, 100, 100 )


previewSpectogram->setColorMap(new previewColorMap(pa, pd));
previewSpectogram->setData(new previewMatrixData(rasterMatrix, Nx, Ny, dx, dy, pd));
previewPlot->axisWidget(QwtPlot::yRight)->setTitle(tr("Intensität"));
previewPlot->axisWidget(QwtPlot::yRight)->setColorBarEnabled(true);
previewPlot->axisWidget(QwtPlot::yRight)->setColorMap(QwtInterval(pa/1e6, pd/1e6), new previewColorMap(pa/1e6,pd/1e6));
previewPlot->setAxisScale(QwtPlot::yRight, pa/1e6, pd/1e6);
previewPlot->enableAxis(1, true);

previewPlot->setAxisScale(QwtPlot::xTop, 0.0 , x*1e3);
previewPlot->setAxisMaxMinor(QwtPlot::xTop, 5);
previewPlot->setAxisScale(QwtPlot::yLeft, y*1e3, 0.0);
previewPlot->setAxisMaxMinor(QwtPlot::yLeft, 5);

previewPlot->replot();
}

Uwe
25th August 2011, 09:36
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:


previewSpectrogram->setAxes( QwtPlot::xTop, QwtPlot::yLeft );

Uwe