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()
#2
Your function used for plotting error-bars doesn't include any specific information, so you can just call plt.errorbar once
within 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 similar
You can also rewrite your savetxt function in a similar way.
Reply


Messages In This Thread
RE: Help with simplifying a code + np.savetxt() - by scidam - Jul-17-2020, 04:29 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [fixed] method overload using np.savetxt paul18fr 3 1,652 Oct-15-2024, 05:56 AM
Last Post: paul18fr
  issue with numpy.savetxt alyssaantarctica 1 4,912 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