I needed to draw 3-d graphs using C code. For this purpose i have to include the matplotlib of Python. Anyone help to do this?? I have to plot the graph on the values currently placed in an array of C.
Asked
Active
Viewed 4,820 times
0
-
Could you clarify the use of C? Matplotlib is a Python library. It can make very nice 3dplots using the `mplot3d` portion of matplotlib. – roadrunner66 Apr 16 '16 at 21:55
-
I mean i need to plot the graphs using matplotlib in C language. I don't know how to do this? On the internet the solutions are ambiguous i could not understand? – Ali Hassan Apr 17 '16 at 08:26
1 Answers
3
Although not exactly the same question you might want to take a look into this.
That being said some of the solutions proposed are:
A) That you include Python on you C program (by @Raj):
#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;
}
B) That you use libraries that mimic matplotlib (by @kazemakase):
As for the array issue, depending on the solution that you chose, it might be worth your while to look into this question. In here @en_Knight provide a few recipes for transforming data (C to Python and vice-versa). Example:
int* my_data_to_modify;
if (PyArg_ParseTuple(args, "O", &numpy_tmp_array)){
/* Point our data to the data in the numpy pixel array */
my_data_to_modify = (int*) numpy_tmp_array->data;
}