Python savefig to directory [closed]
I'm trying to save some plots I make using matplotlib.pyplot however the save location is completely wrong. I'm using a service to plot a couple of values. To be more clear my code:
def plot_results(req):
t = np.arange(0., req.tau+req.dt, req.dt)
print len(t)
fig = plt.figure(1)
plt.plot(t, req.x, 'b-', t, req.y, 'r-')
plt.xlabel('time')
plt.ylabel('x,y')
plt.title('Plot of resulting x and y trajectory')
# plt.show()
path = '~/PyPlots/'
if not os.path.isdir(path): os.makedirs(path)
filename = 'plot%d.png' % req.cycle
filename = os.path.join(path, filename)
fig.savefig(filename)
resp = plot_resultResponse()
resp.succes = 1
return resp
However the figures don't show up in the given directory. First I had an error that the directory didn't exist that's why I added the check and if it doesn't exist, the directory is created. After searching my filesystem it appears that the directory that is created is /proc/pid_of_server/cwd/~/PyPlots/ in which the plots can be found.
Am I doing something wrong or is this a bug in ROS? Personally I think it is the second because I just follow the python docs (not enough karma to link).
If there is a solution, please let me know.