UweQt Code:
To copy to clipboard, switch view to plain text mode
UweQt Code:
To copy to clipboard, switch view to plain text mode
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
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
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.
If all you want is to invert the y axis:
In case of using autoscaling this can be done with setting the QwtScaleEngine::Inverted attribute.Qt Code:
//setAxisScale(QwtPlot::yLeft, 1.0, 7.0);To copy to clipboard, switch view to plain text mode
Uwe
johnMick (25th July 2011)
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?
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:
UweQt Code:
#if 0 #else #endifTo copy to clipboard, switch view to plain text mode
johnMick (26th July 2011)
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?
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
Bookmarks