alainstgt
20th March 2012, 22:09
Hello to everyone,
I have written a piece of code to show the result of a frequency spectrum computation.
The curve is well plotted, but I am missing the legend. I tried out several variants, but nothing helped.
See the code below:
// plot object
QwtPlot myPlot;
myPlot.setTitle( "Autospektrum!" );
myPlot.setAxisTitle( QwtPlot::xBottom, "frequency bin" );
myPlot.setAxisTitle( QwtPlot::yLeft, "log Amplitude" );
myPlot.setCanvasBackground( QColor( Qt::darkBlue ));
// grid
QwtPlotGrid grid;
grid.enableXMin(true);
grid.setMajPen( QPen( Qt::white, 0, Qt::DotLine ));
grid.setMinPen( QPen( Qt::gray, 0 , Qt::DotLine ));
grid.attach( &myPlot );
// define the curve object
QwtPlotCurve curve;
curve.setSamples( pXData, pResults, FFT_LENGTH );
curve.setPen( QPen( Qt::yellow ));
curve.setRenderHint( QwtPlotItem::RenderAntialiased );
curve.setLegendAttribute( QwtPlotCurve::LegendShowLine );
curve.attach( &myPlot );
// legend
QwtLegend legend;
legend.setItemMode( QwtLegend::ReadOnlyItem );
QwtLegendItem legendItem;
legendItem.setText( QwtText( "Autospektrum" ));
myPlot.insertLegend( &legend, QwtPlot::RightLegend );
myPlot.replot();
myPlot.show();
I have written a piece of code to show the result of a frequency spectrum computation.
The curve is well plotted, but I am missing the legend. I tried out several variants, but nothing helped.
See the code below:
// plot object
QwtPlot myPlot;
myPlot.setTitle( "Autospektrum!" );
myPlot.setAxisTitle( QwtPlot::xBottom, "frequency bin" );
myPlot.setAxisTitle( QwtPlot::yLeft, "log Amplitude" );
myPlot.setCanvasBackground( QColor( Qt::darkBlue ));
// grid
QwtPlotGrid grid;
grid.enableXMin(true);
grid.setMajPen( QPen( Qt::white, 0, Qt::DotLine ));
grid.setMinPen( QPen( Qt::gray, 0 , Qt::DotLine ));
grid.attach( &myPlot );
// define the curve object
QwtPlotCurve curve;
curve.setSamples( pXData, pResults, FFT_LENGTH );
curve.setPen( QPen( Qt::yellow ));
curve.setRenderHint( QwtPlotItem::RenderAntialiased );
curve.setLegendAttribute( QwtPlotCurve::LegendShowLine );
curve.attach( &myPlot );
// legend
QwtLegend legend;
legend.setItemMode( QwtLegend::ReadOnlyItem );
QwtLegendItem legendItem;
legendItem.setText( QwtText( "Autospektrum" ));
myPlot.insertLegend( &legend, QwtPlot::RightLegend );
myPlot.replot();
myPlot.show();