Last active
December 18, 2015 02:29
-
-
Save wiless/5711253 to your computer and use it in GitHub Desktop.
KPlotWidget test code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QApplication> | |
#include <QDialog> | |
#include <QHBoxLayout> | |
#include <KPlotWidget> | |
#include <KPlotObject> | |
#include <KPlotAxis> | |
#include <KPlotPoint> | |
#include <itpp/itbase.h> | |
int main(int argn,char *argc[]) | |
{ | |
QApplication app(argn,argc); | |
QDialog *dlg=new QDialog; | |
QHBoxLayout *hlayout=new QHBoxLayout(dlg); | |
dlg->setFixedWidth (1000); | |
dlg->setFixedHeight (700); | |
// Create a new KPlotWidget, provide a minimum size, | |
// and activate antialiased drawing: | |
KPlotWidget *plot = new KPlotWidget(); | |
hlayout->addWidget (plot); | |
plot->setMinimumSize( 400, 400 ); | |
plot->setAntialiasing( true ); | |
// Set the boundaries of the plot to display the full extent of the sine curve: | |
// Create a KPlotObject which will display data | |
// points by connecting them with red line segments | |
// with a width of 2 pixels: | |
KPlotObject *plotcurve = new KPlotObject( Qt::red, KPlotObject::Lines, 2 ); | |
itpp::vec dist="42.500 57.500 72.500 87.500 102.500 117.500 132.500 147.500 162.500 177.500 192.500 207.500 222.500 237.500 252.500 267.500 282.500 297.500 312.500 327.500 342.500 357.500 372.500 387.500 402.500 417.500 432.500 447.500 462.500 477.500 492.500"; | |
itpp::vec SNR="21.429 21.373 21.271 21.060 20.740 20.425 20.038 19.633 19.246 18.981 18.676 18.347 18.053 17.696 17.077 16.487 15.896 15.316 14.621 13.838 13.137 12.406 11.509 10.776 9.993 9.154 8.478 7.725 7.060 6.470 5.612"; | |
plot->setLimits( min(dist), max(dist), min(SNR), max(SNR) ); /// set limits | |
for(int k=0;k<dist.length ();k++) | |
plotcurve->addPoint (dist[k],SNR[k]); | |
// Add the KPlotObject to the plot: | |
plot->addPlotObject( plotcurve ); | |
// Add a text label to the bottom axis: | |
plot->axis( KPlotWidget::BottomAxis )->setLabel( "Distance in meters" ); | |
plot->setBackgroundColor (Qt::white); | |
plot->setForegroundColor (Qt::blue); | |
plot->setGridColor (Qt::gray); | |
plot->setShowGrid (true); | |
plot->update(); | |
dlg->show (); | |
return app.exec (); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requirements
Build
g++ kplot.cpp -I/usr/include/qt4/QtGui -I/usr/include/KDE -I /usr/include/qt4 -litpp -lkdeui