Xan*_*lip 13 c++ binding interface matplotlib
我想知道是否有一个可以在C++中使用的matplotlib接口.(也许类似于gnuplot的东西)
Lei*_*sen 10
基于此SO问题,您可以使用字符串:
对于静态数据,它非常简单:
#include "Python.h"
int main()
{
Py_Initialize();
PyRun_SimpleString("import pylab");
PyRun_SimpleString("pylab.plot(range(5))");
PyRun_SimpleString("pylab.show()");
Py_Exit(0);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它变得有点棘手,但仍然可以使用可变数据,只需将它连接到一个字符串即可.
#include <string>
#include "Python.h"
using namespace std;
int main()
{
Py_Initialize();
int x[5] = {0, 1, 2, 3, 4};
int y[5] = {5, 1, 7, 5, 1};
string command = "pylab.plot([";
for(int i = 0; i < 4; i++) {
command += x[i];
command += ", ";
}
command += x[4];
command += "], [";
for(int i = 0; i < 4; i++) {
command += y[i];
command += ", ";
}
command += y[4];
command += "])";
PyRun_SimpleString("import pylab");
PyRun_SimpleString(command.c_str());
PyRun_SimpleString("pylab.show()");
Py_Exit(0);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
(请注意,我没有检查这个错误,所以可能有一些在那里,但你明白了,是的,这是一个非常难看的解决方案).
归档时间: |
|
查看次数: |
7910 次 |
最近记录: |