I need to save the output of the function to a file with a name of the variable passed to that function. I have tried using a function from a stackoverflow user.
def var_name(**variables):
return [x for x in variables]
My code as follows,
dist
is numpy array dataset containing different arrays.
MTnum=10
import matplotlib.pyplot as plt
import numpy as np
def Plot(dist, sav=False):
MT_dat = np.vsplit(dist,MTnum)
for i,mtdat in enumerate(MT_dat):
plt.figure(i)
for j in range(len(mtdat[0])-1):
plt.plot(MT_dat[i][:,0],MT_dat[i][:,j+1])
plt.xlabel('time')
plt.ylabel('distance')
plt.title('MT_'+str(i+1)+var_name(dist=dist)+'.png')
if sav == True:
plt.savefig('MT_'+str(i+1)+var_name(dist=dist)+'.png')
plt.show()
If I use function Plot(set1)
,files are saved with "dist" suffix instead of "set1". Please suggest a proper way of doing it.