Python Forum
Help with simplifying a code + np.savetxt()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with simplifying a code + np.savetxt()
#3
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:

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.
Reply


Messages In This Thread
RE: Help with simplifying a code + np.savetxt() - by Laplace12 - Jul-20-2020, 08:03 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  issue with numpy.savetxt alyssaantarctica 1 3,980 Jul-13-2018, 03:50 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020