Jul-17-2020, 04:29 AM
Your function used for plotting error-bars doesn't include any specific information, so you can just call
within
plt.errorbar
oncewithin
plot_data
:def plot_data(energy, ydata, figname): fig = plt.figure() plt.errorbar(energy, ydata[:,0], yerr=ydata[:,1]) plt.ylabel('x') plt.xlabel('y') plt.legend() plt.savefig(figname, Transparent = True) # Transparend (first letter is uppercased? ) plt.close('all')In the main code you can do the following:
# define an auxiliary variable what_to_plot = ['area', 'offset'] for what in what_to_plot: plot_data(energy, locals().get(what), what + '-fig.png') # or something similarYou can also rewrite your
savetxt
function in a similar way.