Example code to read a file and make some plots.
More...
Example code to read a file and make some plots.
2 \namespace xboa::examples::Example_2
4 Example code to read a file and make some plots
6 \include xboa/examples/Example_2.py
25 filename = sys.prefix+
'/share/xboa/data/for009.dat'
26 filetype =
"icool_for009"
28 print '========= XBOA example 2 ========='
33 print "This example shows how to make plots\nYou will need to have access to either ROOT library or the matplotlib library to make plots"
34 print "First loading the data... "
35 bunch_list = Bunch.new_list_from_read_builtin(filetype, filename)
41 print 'Trying to make some plots using PyROOT plotting package'
44 bunch_list[0] .root_histogram(
'p',
'MeV/c')
45 bunch_list[-1].root_histogram(
'p',
'MeV/c')
48 bunch_list[0].root_scatter_graph(
't',
'energy',
'ns',
'MeV/c')
53 bunch_list[0].root_histogram(
't',
'ns',
'energy',
'MeV/c')
54 (canvas, hist) = bunch_list[0] .root_histogram(
't',
'ns',
'energy',
'MeV/c')
59 Bunch.root_graph(bunch_list,
'mean', [
'z'],
'emittance', [
'x'],
'm',
'mm')
60 Bunch.root_graph(bunch_list,
'mean', [
'z'],
'emittance', [
'x',
'y'],
'm',
'mm')
62 print "PyROOT not detected - skipping PyROOT graphics"
66 print 'Trying to make some plots using matplotlib plotting package'
69 bunch_list[0] .matplot_histogram(
'p',
'MeV/c')
70 bunch_list[-1].matplot_histogram(
'p',
'MeV/c')
73 bunch_list[0].matplot_scatter_graph(
't',
'energy',
'ns',
'MeV/c')
78 bunch_list[0].matplot_histogram(
't',
'ns',
'energy',
'MeV/c')
81 Bunch.matplot_graph(bunch_list,
'mean', [
'z'],
'emittance', [
'x'],
'm',
'mm')
82 Bunch.matplot_graph(bunch_list,
'mean', [
'z'],
'emittance', [
'x',
'y'],
'm',
'mm')
85 common.show_matplot_and_continue()
89 print "Matplotlib not detected - skipping matplotlib graphics"
93 print 'Press <return> key to finish'
string filename = sys.prefix+'/share/xboa/data/for009.dat' |
string filetype = "icool_for009" |