Skip to content

Instantly share code, notes, and snippets.

@csullivan
Last active August 29, 2015 14:25
Show Gist options
  • Save csullivan/b045de44ad544d7d0044 to your computer and use it in GitHub Desktop.
Save csullivan/b045de44ad544d7d0044 to your computer and use it in GitHub Desktop.
py.python_import("pylab","plot");
py.python_import("pylab","savefig");
vector<float> rand;
py.__py("import numpy as np; import pylab");
// create an arbitrary list in python and extract it out into c++ land
py.__py("x = [float(x) for x in np.random.rand(10)]","x",rand);
for(int i=0;i<rand.size();i++){
cout << rand[i] << endl;
}
// send it back to python as a new list
py.functions["plot"](py.VecToList(rand),py.VecToList(rand));
py.__py("pylab.xlim(0.1,0.5)");
// call savefig via c++ function
py.functions["savefig"]("./test.pdf");
// or via python
py.__py("pylab.savefig('./test.pdf')");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment