如何使用 C++ 程序中的 gnuplot 绘制图形
how to plot a graph using gnuplot from C++ program
以下是我用来将数据(x 和 y 坐标)写入文件的代码。
void display(){
fstream out;
outfile.open("Co_ordinates.txt",fstream::out | fstream::trunc);
outfile.precision(6);
for(int i=0;i<3000; i++){
outfile<<fixed<<x[i]<<" "<<fixed<<y[i]<<endl;
}
out.close();
}
我想使用上述文件中的 x 和 y 坐标绘制图表 "Co_ordinates.txt" 我添加了来自 https://code.google.com/p/gnuplot-cpp/source/browse/trunk/gnuplot_i.hpp 的 gnuplot 实用程序 "gnuplot_i.hpp"。
我使用了 gnuplot_i.hpp
中定义的以下函数
/// plot x,y pairs: x y
/// from file
Gnuplot& plotfile_xy(const std::string &filename,
const unsigned int column_x = 1,
const unsigned int column_y = 2,
const std::string &title = "");
我添加了以下代码来绘制图表
const string s="Co_ordinates.txt";
Gnuplot& plotfile_xy(&s,1,2,'Grid');
但是出现以下错误
错误:表达式列表在初始值设定项 [-fpermissive] 中被视为复合表达式|
错误:从类型“int”|
的右值对类型“Gnuplot&”的非常量引用进行无效初始化
我已经尝试了多种形式的上述代码..但出现错误。
请提出一些解决方案..
plotfile_xy
是Gnuplot
class的成员函数,所以要调用它你需要一个[=12=的实例],例如:
Gnuplot gp("lines");
//using the parameters from your code
gp.plotfile_xy(&s,1,2,'Grid');
文档的方式不多,但是您是否注意到有一个示例程序可以演示很多功能?
https://code.google.com/p/gnuplot-cpp/source/browse/trunk/example.cc
我所做的全部事情都可以使用以下代码轻松完成
system("gnuplot -p -e \"plot 'Co_ordinates.txt'\"");
以下是我用来将数据(x 和 y 坐标)写入文件的代码。
void display(){
fstream out;
outfile.open("Co_ordinates.txt",fstream::out | fstream::trunc);
outfile.precision(6);
for(int i=0;i<3000; i++){
outfile<<fixed<<x[i]<<" "<<fixed<<y[i]<<endl;
}
out.close();
}
我想使用上述文件中的 x 和 y 坐标绘制图表 "Co_ordinates.txt" 我添加了来自 https://code.google.com/p/gnuplot-cpp/source/browse/trunk/gnuplot_i.hpp 的 gnuplot 实用程序 "gnuplot_i.hpp"。
我使用了 gnuplot_i.hpp
中定义的以下函数/// plot x,y pairs: x y
/// from file
Gnuplot& plotfile_xy(const std::string &filename,
const unsigned int column_x = 1,
const unsigned int column_y = 2,
const std::string &title = "");
我添加了以下代码来绘制图表
const string s="Co_ordinates.txt";
Gnuplot& plotfile_xy(&s,1,2,'Grid');
但是出现以下错误
错误:表达式列表在初始值设定项 [-fpermissive] 中被视为复合表达式| 错误:从类型“int”|
的右值对类型“Gnuplot&”的非常量引用进行无效初始化我已经尝试了多种形式的上述代码..但出现错误。 请提出一些解决方案..
plotfile_xy
是Gnuplot
class的成员函数,所以要调用它你需要一个[=12=的实例],例如:
Gnuplot gp("lines");
//using the parameters from your code
gp.plotfile_xy(&s,1,2,'Grid');
文档的方式不多,但是您是否注意到有一个示例程序可以演示很多功能? https://code.google.com/p/gnuplot-cpp/source/browse/trunk/example.cc
我所做的全部事情都可以使用以下代码轻松完成
system("gnuplot -p -e \"plot 'Co_ordinates.txt'\"");