Jul-20-2020, 08:03 AM
Hey, thanks!
The plotting seems to work now, but I seem to have lost the plot as it is now just a straight line at 00.00 and doesn't show any peaks. The code now looks like this:
The plotting seems to work now, but I seem to have lost the plot as it is now just a straight line at 00.00 and doesn't show any peaks. The code now looks like this:
def plot_data(x, ydata, figname): fig = plt.figure() plt.errorbar(x, ydata[:,0], yerr=ydata[:,1]) plt.ylabel('x') plt.xlabel('y') plt.legend() plt.savefig(figname, Transparent = True) # plt.close('all') def savetxt(name, x, ydata): np.savetxt(name + '.data', what) np.savetxt(file, np.transpose(([x, area[:,0], area[:,0]])), header='Energy I0 I1 {}'.format(name))With this in the main code, fn being the name I called the functions file with:
what_to_plot = ['area'] what_to_save = ['area', 'offset', 'width', 'center', 'data'] for what in what_to_plot: fn.plot_data(x, locals().get(what), what + '-fig.png') for what in what_to_save: fn.savetxt(x, locals().get(what), name + what + '.data')There is another problem in the savetxt function, with this error regarding the 'np.savetxt(name + '.data', what)' line:
UFuncTypeError: ufunc 'add' did not contain a loop with signature matching types (dtype('<U11'), dtype('<U11')) -> dtype('<U11')I have no idea what this error means, only that there must be something wrong with the command I tried to assign.