安装
1 2
| sudo apt-get install gnuplot sudo apt-get install gnuplot-x11
|
输入 gnuplot
,出现命令行,输入 plot sin(x)
,如果出现正弦曲线说明安装成功。
下载地址
解压gnuplot-cpp,输入 make 进行编译。如果在其它项目需要使用gnuplot将gnuplot_i.hpp
复制到对应项目,在程序中加入 #include "gnuplot_i.hpp"
, 无需链接什么动态库, 这也是我使用它的主要原因,懒得改CMake
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| Gnuplot g1;
void plot(const vector<double>& Xs, const vector<double>& Ys, const string& comment, const string& style) { g1.set_grid(); g1.set_pointsize(1.5); g1.set_style(style).plot_xy(Xs, Ys, comment); }
void wait_for_key() { cout << "Press Enter to continue ..." <<endl; cin.clear(); cin.ignore(cin.rdbuf()->in_avail() ); cin.get(); return; }
g1.set_style("points").plot_xy(Xs, Ys, "spine_name");
g1.set_xlabel("radar x /m"); g1.set_ylabel("radar y /m");
|
参考:C++ 调用Gnuplot实现图形绘制的过程