0

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.

2
  • Could you clarify the use of C? Matplotlib is a Python library. It can make very nice 3dplots using the mplot3d portion of matplotlib. Commented Apr 16, 2016 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? Commented Apr 17, 2016 at 8:26

1 Answer 1

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):

matplotlib-cpp

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;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.