2 \namespace xboa::examples::Example_2
4 Example code to read a file and make some plots
6 \include xboa/examples/Example_2.py
24 filename = sys.prefix+
'/share/xboa/data/for009.dat'
25 filetype =
"icool_for009"
27 print '========= XBOA example 2 ========='
32 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"
33 print "First loading the data... "
34 bunch_list = Bunch.new_list_from_read_builtin(filetype, filename)
40 print 'Trying to make some plots using PyROOT plotting package'
43 bunch_list[0] .root_histogram(
'p',
'MeV/c')
44 bunch_list[-1].root_histogram(
'p',
'MeV/c')
47 bunch_list[0].root_scatter_graph(
't',
'energy',
'ns',
'MeV/c')
52 bunch_list[0].root_histogram(
't',
'ns',
'energy',
'MeV/c')
53 (canvas, hist) = bunch_list[0] .root_histogram(
't',
'ns',
'energy',
'MeV/c')
58 Bunch.root_graph(bunch_list,
'mean', [
'z'],
'emittance', [
'x'],
'm',
'mm')
59 Bunch.root_graph(bunch_list,
'mean', [
'z'],
'emittance', [
'x',
'y'],
'm',
'mm')
61 print "PyROOT not detected - skipping PyROOT graphics"
65 print 'Trying to make some plots using matplotlib plotting package'
68 bunch_list[0] .matplot_histogram(
'p',
'MeV/c')
69 bunch_list[-1].matplot_histogram(
'p',
'MeV/c')
72 bunch_list[0].matplot_scatter_graph(
't',
'energy',
'ns',
'MeV/c')
77 bunch_list[0].matplot_histogram(
't',
'ns',
'energy',
'MeV/c')
80 Bunch.matplot_graph(bunch_list,
'mean', [
'z'],
'emittance', [
'x'],
'm',
'mm')
81 Bunch.matplot_graph(bunch_list,
'mean', [
'z'],
'emittance', [
'x',
'y'],
'm',
'mm')
84 Common.show_matplot_and_continue()
87 print 'Press ctrl-C to continue'
88 Common.wait_for_matplot()
92 print "Matplotlib not detected - skipping matplotlib graphics"
96 print 'Press <return> key to finish'