2018-12-29 00:46:47 +08:00
|
|
|
#include "TestWidgetContourPlots.h"
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QDate>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QApplication>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TestWidgetContourPlots::TestWidgetContourPlots(QWidget *parent) :
|
|
|
|
QWidget(parent)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
// contour plot
|
2019-06-21 21:46:53 +08:00
|
|
|
QHBoxLayout* layoutContour=new QHBoxLayout();
|
2018-12-29 00:46:47 +08:00
|
|
|
setLayout(layoutContour);
|
2019-01-20 23:15:10 +08:00
|
|
|
JKQTPlotter* plotContour=new JKQTPlotter(true, this);
|
2019-01-26 03:16:04 +08:00
|
|
|
plotContour->setPlotUpdateEnabled(false);
|
|
|
|
plotContour->getPlotter()->setPlotLabel(tr("\\textbf{hist contour plot}"));
|
2018-12-29 00:46:47 +08:00
|
|
|
plotContour->setObjectName("contour");
|
2019-01-26 03:16:04 +08:00
|
|
|
plotContour->getPlotter()->setUserSettigsFilename(QApplication::applicationDirPath()+"/usersettings.ini", "contour/");
|
2018-12-29 00:46:47 +08:00
|
|
|
layoutContour->addWidget(plotContour);
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
JKQTPlotter* plotDensity=new JKQTPlotter(true, this);
|
2019-01-26 03:16:04 +08:00
|
|
|
plotContour->setPlotUpdateEnabled(false);
|
|
|
|
plotContour->getPlotter()->setPlotLabel(tr("\\textbf{2D histogram plot with contours}"));
|
|
|
|
plotDensity->getPlotter()->setPlotLabel(tr("\\textbf{2D histogram}"));
|
2018-12-29 00:46:47 +08:00
|
|
|
plotContour->setObjectName("density");
|
2019-01-26 03:16:04 +08:00
|
|
|
plotContour->getPlotter()->setUserSettigsFilename(QApplication::applicationDirPath()+"/usersettings.ini", "density/");
|
2018-12-29 00:46:47 +08:00
|
|
|
layoutContour->addWidget(plotDensity);
|
|
|
|
|
|
|
|
QVector<double> histAlex;
|
2019-06-22 20:21:32 +08:00
|
|
|
size_t histAlexNx,histAlexNy;
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// choose the test data
|
|
|
|
histAlex.clear();
|
|
|
|
histAlex.resize(5);
|
|
|
|
histAlex.append(15.0);
|
|
|
|
histAlex.append(5);
|
|
|
|
histAlex.append(0);
|
|
|
|
histAlex.append(0);
|
|
|
|
histAlex.append(5);
|
|
|
|
histAlex.append(15);
|
|
|
|
histAlex.append(6);
|
|
|
|
histAlex.append(6);
|
|
|
|
histAlex.resize(16);
|
|
|
|
|
2019-06-22 20:21:32 +08:00
|
|
|
histAlexNx=(size_t)sqrt(histAlex.size());
|
2018-12-29 00:46:47 +08:00
|
|
|
histAlexNy=histAlexNx;
|
|
|
|
|
2019-01-26 03:16:04 +08:00
|
|
|
auto ds=plotDensity->getPlotter()->getDatastore();
|
|
|
|
plotContour->getPlotter()->useExternalDatastore(ds);
|
2018-12-29 00:46:47 +08:00
|
|
|
// empty datastore and grid
|
2019-01-26 03:16:04 +08:00
|
|
|
plotDensity->getPlotter()->clearGraphs(true);
|
2018-12-29 00:46:47 +08:00
|
|
|
ds->clear();
|
|
|
|
plotDensity->setGrid(false);
|
2019-01-26 03:16:04 +08:00
|
|
|
plotDensity->getPlotter()->getXAxis()->setAxisLabel("X");
|
|
|
|
plotDensity->getPlotter()->getYAxis()->setAxisLabel("Y");
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
size_t colHist2D=ds->addCopiedImageAsColumn(histAlex.data(), histAlexNx, histAlexNy, tr("2Dhist"));
|
|
|
|
// size_t colContour=plotContour->getDatastore()->addCopiedImageAsColumnTranspose(histAlex.data(), histAlexNx, histAlexNy, tr("2Dhist"));
|
|
|
|
|
2019-01-26 03:16:04 +08:00
|
|
|
JKQTPColumnMathImage* densityplot=new JKQTPColumnMathImage(plotDensity->getPlotter());
|
2019-01-26 20:00:40 +08:00
|
|
|
densityplot->setX(-0.1);
|
|
|
|
densityplot->setY(-0.1);
|
|
|
|
densityplot->setWidth(1.1);
|
|
|
|
densityplot->setHeight(1.1);
|
|
|
|
densityplot->setNx(histAlexNx);
|
|
|
|
densityplot->setNy(histAlexNy);
|
|
|
|
densityplot->setPalette(JKQTPMathImageINVERTED_OCEAN);
|
|
|
|
densityplot->setImageColumn(colHist2D);
|
|
|
|
densityplot->setInfColor(Qt::transparent);
|
|
|
|
densityplot->setNanColor(Qt::transparent);
|
|
|
|
densityplot->setTitle("density plot");
|
2018-12-29 00:46:47 +08:00
|
|
|
plotDensity->addGraph(densityplot);
|
|
|
|
|
2019-01-26 03:16:04 +08:00
|
|
|
densityplot=new JKQTPColumnMathImage(plotContour->getPlotter());
|
2019-01-26 20:00:40 +08:00
|
|
|
densityplot->setX(-0.1);
|
|
|
|
densityplot->setY(-0.1);
|
|
|
|
densityplot->setWidth(1.1);
|
|
|
|
densityplot->setHeight(1.1);
|
|
|
|
densityplot->setNx(histAlexNx);
|
|
|
|
densityplot->setNy(histAlexNy);
|
|
|
|
densityplot->setPalette(JKQTPMathImageINVERTED_OCEAN);
|
|
|
|
densityplot->setImageColumn(colHist2D);
|
|
|
|
densityplot->setTitle("density plot");
|
2018-12-29 00:46:47 +08:00
|
|
|
plotContour->addGraph(densityplot);
|
|
|
|
plotContour->setGrid(false);
|
|
|
|
plotDensity->zoom(-0.1,1.1,-0.1,1.1);
|
|
|
|
|
2019-05-19 04:41:38 +08:00
|
|
|
QVector<double> levels;
|
2018-12-29 00:46:47 +08:00
|
|
|
// levels<<5<<10<<25; // levels<<5.1<<10.1;
|
|
|
|
levels<<4<<5<<9<<14;
|
2019-05-19 04:41:38 +08:00
|
|
|
JKQTPColumnContourPlot* cp=new JKQTPColumnContourPlot(plotContour->getPlotter());
|
2019-01-26 20:00:40 +08:00
|
|
|
cp->setX(-0.1);
|
|
|
|
cp->setY(-0.1);
|
|
|
|
cp->setWidth(1.1);
|
|
|
|
cp->setHeight(1.1);
|
|
|
|
cp->setNx(histAlexNx);
|
|
|
|
cp->setNy(histAlexNy);
|
|
|
|
cp->setImageColumn(colHist2D);
|
|
|
|
// cp->setPalette(JKQTPMathImageINVERTED_OCEAN);
|
|
|
|
cp->setContourLevels(levels);
|
|
|
|
cp->setTitle("contour plot");
|
2018-12-29 00:46:47 +08:00
|
|
|
plotContour->addGraph(cp);
|
|
|
|
plotContour->zoom(-0.1,1.1,-0.1,1.1);
|
|
|
|
|
2019-01-26 03:16:04 +08:00
|
|
|
plotContour->setPlotUpdateEnabled(true);
|
2019-01-26 19:28:44 +08:00
|
|
|
plotContour->redrawPlot();
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|