source: trunk/templates/sourcespectrum.html

Last change on this file was 50, checked in by JohnLightfoot, 10 years ago

almost working

File size: 1.2 KB
Line 
1<%inherit file="base.html"/>
2
3<!-- do the plotting -->
4<%
5import matplotlib.pyplot as plt
6import os.path
7import numpy as np
8
9plt.figure()
10
11sourceid = context['sourceid']
12spectrum = context['spectrum']
13
14try:
15 xaxis_data = spectrum.axis.data
16except:
17 xaxis_data = np.arange(len(spectrum.data))
18
19# sometimes xaxis is not monotonic
20xaxis_sort = np.argsort(xaxis_data)
21
22try:
23 xaxis_title = spectrum.axis.title
24except:
25 xaxis_title = None
26
27try:
28 xaxis_units = spectrum.axis.units
29except:
30 xaxis_units = None
31
32if spectrum.data.dtype==np.complex:
33 plt.plot(xaxis_data[xaxis_sort], spectrum.data.real[xaxis_sort],
34 color='blue')
35 plt.plot(xaxis_data[xaxis_sort], spectrum.data.imag[xaxis_sort],
36 color='red')
37 plt.figtext(0.2, 0.25, 'real', color='blue')
38 plt.figtext(0.2, 0.2, 'imag', color='red')
39else:
40 plt.plot(xaxis_data[xaxis_sort], spectrum.data[xaxis_sort])
41
42plt.title('Source %s' % sourceid)
43xlabel = ' '.join([v for v in [xaxis_title, xaxis_units] if v is not None])
44plt.xlabel(xlabel)
45
46plt.savefig(os.path.join(context['dirname'], 'sourcespectrum%s.png' % sourceid))
47plt.close()
48%>
49
50<!-- link to the plot from html -->
51
52<img src='sourcespectrum${sourceid}.png' alt="Source spectrum">
Note: See TracBrowser for help on using the repository browser.