### 什么是*绘制* std :: vector <double>的简单/最简单的方法？

4803 观看

5回复

1841 作者的声誉

`````` std::vector<double> X = some_math_function( );
somenamespace :: plot(  Wrapper( X ) ); // pop-up and display a graph of X on y-axis, 1 to X.size() on x-axis.
``````

### 回应 (5)

3

3429 作者的声誉

koolplot

GOBLIN

6

11796 作者的声誉

``````//untested
ofstream myfilestream("myfile");
std::copy(X.begin(), X.end(), std::ostream_iterator<double>(myfilestream, '\n');
``````

``````gnuplot
plot "myfile" with lines
``````

-1

6819 作者的声誉

2

767 作者的声誉

``````mglGraphZB gr;// create canvas
mglData d; d.Set(X);  // convert to internal format
gr.YRange(d); // set range for y-axis
gr.Plot(d);   // plot it
gr.Axis();    // draw axis if you need
gr.WritePNG("1.png"); // save it
``````

0

751 作者的声誉

``````#include "matplotlibcpp.h"
#include <vector>
#include <algorithm> // for std::iota

int main()
{
std::vector <double> y = {0.1, 0.2, 0.4, 0.8, 1.6};
std::vector <int> x(y.size());
std::iota(x.begin(), x.end(), 0);

matplotlibcpp::plot(x, y);
matplotlibcpp::show();
plt::save("plot.png");
}
``````

``````find_package(PythonLibs 2.7)
target_include_directories(myproject PRIVATE \${PYTHON_INCLUDE_DIRS})
``````g++ main.cpp -std=c++11 -I/usr/include/python2.7 -lpython2.7