Created
January 19, 2016 07:52
-
-
Save qtneko/e53cb41cd2800adf776f to your computer and use it in GitHub Desktop.
gnuplot
This file contains hidden or 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 "mainwindow.h" | |
MainWindow::MainWindow(QWidget *parent) | |
: QMainWindow(parent) | |
{ | |
//Создаем главный виджет | |
QWidget *main = new QWidget; | |
setCentralWidget(main); | |
//На главном виджете размещаем вертикальный layout | |
QVBoxLayout *main_layout = new QVBoxLayout; | |
main->setLayout(main_layout); | |
QLabel *lbl = new QLabel; | |
lbl->setText("f(x,y)="); | |
main_layout->addWidget(lbl); | |
//Поле для ввода выражения f(x,y) | |
expr = new QLineEdit; | |
expr->setText("x**2 + y**2"); | |
main_layout->addWidget(expr); | |
//Кнопка отрисовки графика для выражения f(x,y) | |
plot_expr = new QPushButton; | |
plot_expr->setText("Plot expression"); | |
main_layout->addWidget(plot_expr); | |
connect(plot_expr, SIGNAL(clicked()), this, SLOT(on_plot_expr())); | |
//Кнопка отрисовки заданного массива | |
plot_array = new QPushButton; | |
plot_array->setText("Plot array"); | |
main_layout->addWidget(plot_array); | |
connect(plot_array, SIGNAL(clicked()), this, SLOT(on_plot_array())); | |
} | |
MainWindow::~MainWindow() | |
{ | |
} | |
void MainWindow::on_plot_expr() | |
{ | |
#ifdef _WIN32 | |
Gnuplot gp("gnuplot.exe -persist"); | |
#else | |
Gnuplot gp; | |
#endif | |
gp << "f(x,y)=" << expr->text().toStdString() << "\n"; | |
gp << "splot f(x,y) with pm3d palette title 'f(x,y)=" << expr->text().toStdString() << "'\n"; | |
} | |
void MainWindow::on_plot_array() | |
{ | |
#ifdef _WIN32 | |
Gnuplot gp("gnuplot.exe -persist"); | |
#else | |
Gnuplot gp; | |
#endif | |
int size = 100; | |
QVector<QVector<double> > arr(size*size); | |
for (int i = 0; i < size; ++i) | |
for (int j = 0; j < size; ++j) | |
{ | |
arr[j + size*i].append(i); | |
arr[j + size*i].append(j); | |
arr[j + size*i].append((i*i - j*j)/size); | |
} | |
gp << "f(x,y)=" << expr->text().toStdString() << "\n"; | |
gp << "splot '-' with dots palette title 'Plotting the array'\n"; | |
gp.send1d(arr); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment