Winston Lutz Individual images

Hello Everyone,

Can anyone help me to save Individual plot images from WL test (Create a .png file from some of the analyzed images individually)? What code lines should i write to do it? I just can’t figure it out.

Thanks

Hi Bruno,

below a part of code I use to generate a jpg from a plot of WL profiles.

Some comments:

  • the part with plt.text it is used to superimpose results on the figure (https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.text.html)
  • the jpg name is composed by two parts, one is “field”, that is extracted from a TIFF file (such as gantry0.tif → field = gantry0) and the second is jpg, so that the jpg file is automatically called “gantry0.jpg” for example
  • I set width and height in order to have a specific image size
  • if you want another format you shall specify it in plt.savefig, but I think the default is png (to be checked).

You can take a look here for additional info: https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.savefig.html

I hope this can help you!

Regards,

Andrea

#generate the plot of centered profiles in both direction

fig=plt.figure(‘Profiles WL’)
w=26.666
h=13
fig.set_size_inches(w,h)
row = final[y_c,:]
profile_x = SingleProfile(row)
profile_xx=np.array(profile_x)
col = final[:,x_c]
profile_y = SingleProfile(col)
profile_yy=np.array(profile_y)
figManager = plt.get_current_fig_manager()
figManager.window.showMaximized()
plt.grid(True)
x_set=np.arange(-50,50,10)
y_set=np.arange(0,110,10)
plt.plot(dist_norm_x,profile_xx,color=‘r’, linewidth=1)
plt.plot(dist_norm_y,profile_yy,color=‘b’, linewidth=1)
plt.xticks(x_set)
plt.yticks(y_set)
plt.ylabel(‘Dose%’, fontsize=20)
plt.xlabel(‘Distance (mm)’, fontsize=20)
plt.gca().legend((‘Profile along X’,‘Profile along Y’), fontsize=20)

plt.text(-49, 13.85, ‘WL analysis\n\nField = %s\n\n’ %field+
‘X-Profile\n\nFWHM - proton spot (mm) = %.2f\n’ %FWHM_x+‘FWHM - WL BB (mm) = %.2f\n’%FWHM_x_BB+
‘Delta X - spot (mm) = %.2f\n’%delta_x_spot+‘Delta X - WL BB (mm) = %.2f\n\n’%delta_x_BB+
‘Y-Profile\n\nFWHM - proton spot (mm) = %.2f\n’ %FWHM_y+‘FWHM - WL BB (mm) = %.2f\n’%FWHM_y_BB+
‘Delta Y - spot (mm) = %.2f\n’%delta_y_spot+‘Delta Y - WL BB (mm) = %.2f\n\n’%delta_y_BB+
‘Positioning error (mm) = %.2f’%pos_error,
fontsize=17, bbox=dict(linewidth=2,edgecolor=‘black’,facecolor=‘white’, zorder=10))

str1=field
str2=“.jpg”

field_name=str1+str2

plt.savefig(field_name, dpi=120,quality=72,format=‘jpg’)