Python savefig to directory [closed]

asked 2014-04-28 22:23:31 -0600

Jacco van der Spek gravatar image

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.title('Plot of resulting x and y trajectory')
    path = '~/PyPlots/'
    if not os.path.isdir(path): os.makedirs(path)
    filename = 'plot%d.png' % req.cycle
    filename = os.path.join(path, 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.

edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant. Please see for more details. by tfoote
close date 2018-01-30 20:55:55.020308