📄 gnuplot.h
字号:
#ifndef __gnuplot_h__#define __gnuplot_h__#include <string>#include <vector>#include <iostream>namespace Gnuplot{using std::cout;using std::cerr;using std::endl;using std::vector;using std::string;enum gpmode{ plot2d, plot3d};struct range{ double min, max;};struct gpsettings{ range x, y, z; gpmode mode; string gphead; gpsettings() { x.min = y.min = z.min = -1; x.max = y.max = z.max = 1; mode = plot2d; gphead = ""; } void enableHeadMode { gphead = "GNUPLOT"; }};struct gpobject{ string color; gpobject(string color="gray"): color(color) {}};struct gpbuffer{ vector<gpobject> data;};struct point{ point(double x=0, double y=0): x(x), y(y) {} double x, y;};struct line{ point p0, p1; line(double x0=0, double y0=0, double x1=0, double y1=0): p0(x0,y0), p1(x1,y1) {}};struct gppoint: point, gpobject{ gppoint(double x, double y, string color): point(x,y), gpobject(color) {}};struct gppointvector: gpobject{ vector<point> points;};struct gpline: line, gpobject{ gpline(double x0, double y0, double x1, double y1, string color): line(x0,y0,x1,y1), gpobject(color) {}};struct gplinevector{ vector<line> lines;};gpbuffer buffer;gpsettings settings;void gp_addpoint(double x, double y, string color){ buffer.data.push_back(gppoint(x, y, color));}void gp_addline(double x0, double y0, double x1, double y1, string color){ buffer.data.push_back(gpline(x0, y0, x1, y1, color));}void gp_init(){ buffer.data.clear();}void gp_display(){ cout << gphead << "set mouse" << endl; cout << gphead << "set xrange [" << settings.x.min << ":" << settings.x.max << "]" << endl; cout << gphead << "set yrange [" << settings.y.min << ":" << settings.y.max << "]" << endl; if (settings.mode == plot3d) { cout << gphead << "set zrange [" << settings.z.min << ":" << settings.z.max << "]" << endl; cout << gphead << "splot"; } cout << gphead << "plot"; cout << gphead << " \'-\' w p"; cout << gphead << endl; cout << gphead << "0 0" << endl; cout << gphead << "e" << endl;}}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -