Following is the code I have used to write data (x and y coordinates)into a file.
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();
}
I want to plot the graph using the x and y coordinates from the above file "Co_ordinates.txt" I have added gnuplot utility "gnuplot_i.hpp" from https://code.google.com/p/gnuplot-cpp/source/browse/trunk/gnuplot_i.hpp .
I have used the following function defined in 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 = "");
I have added the following code to plot the graph
const string s="Co_ordinates.txt";
Gnuplot& plotfile_xy(&s,1,2,'Grid');
But getting following errors
error: expression list treated as compound expression in initializer [-fpermissive]| error: invalid initialization of non-const reference of type ‘Gnuplot&’ from an rvalue of type ‘int’|
I have tried the above code in several forms.. but getting errors. Please suggest some solutions..
The whole thing I have done can be easily done using the following code
system("gnuplot -p -e \"plot 'Co_ordinates.txt'\"");
plotfile_xy
is a member function of the Gnuplot
class, so to call it you need an instance of Gnuplot
, for example:
Gnuplot gp("lines");
//using the parameters from your code
gp.plotfile_xy(&s,1,2,'Grid');
There's not much in the way of documentation, but did you notice that there's a sample program that demonstrates a lot of the functions? https://code.google.com/p/gnuplot-cpp/source/browse/trunk/example.cc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With