I want to create a log-log plot using pyplot, but have trouble when calling plt.show()
:
import matplotlib.pyplot as plt
xVec = [...]
yVec = [...]
plt.figure()
plt.loglog(xVec,yVec,'.',label='This is my test plot')
plt.xlabel('x axis')
plt.ylabel('y axis')
plt.show()
I am running this code from C++ via:
Py_Initialize();
Py_SimpleString(pythonCode.str().c_str());
Py_Exit(0);
where pythonCode
is a stringstream
containing the Python code above. The code runs if I don't include the plt.show()
line, but of course no plot shows up.
The matplotlibrc
config file shows that the backend is TkAgg, which shouldn't give problems as indicated here or here. I've tried adding plt.close()
after the last line in the code above, but the error persists.
Perhaps the most surprising thing is this: I've also tried running the code in a separate Python script (with plt.show()
), and the plot appears correctly! Does anyone have any idea about what's going on? Thanks in advance!
EDIT: I have also tried pylab
instead of pyplot
, with the same results. Do I need to compile the program with a certain python
module to link the libraries properly?