ATLAS Offline Software
Loading...
Searching...
No Matches
plot-intgrid.py
Go to the documentation of this file.
1import matplotlib.pyplot as plt
2
3def parse_file_contents(file_content,file_name):
4 # Initialize empty lists for x and y values
5 x_values = []
6 y_values = []
7 title = ""
8
9 # Split the file content into lines
10 lines = file_content.strip().split('\n')
11
12 # Iterate through each line
13 for line in lines:
14 if line.strip().startswith("join"):
15 if title == "":
16 continue
17 print("saving plot "+title)
18 new_x = range(len(x_values))
19 new_x = [i/(len(x_values)-1) for i in new_x]
20 plt.plot(x_values,y_values,"o-")
21 plt.plot(new_x,y_values,"o-")
22 plt.title(title)
23 plt.savefig(title+".png",format="png")
24 plt.close()
25 x_values = []
26 y_values = []
27 title = ""
28 if line.strip().startswith("title"):
29 title = line.split('"')[1]
30 title = title.split()
31 title = file_name+"_dim"+title[1]
32 print("title "+title)
33
34 # Split the line into words (or values)
35 values = line.split()
36 if title == "":
37 continue
38 # Check if the line contains numerical values (excluding title and set limits)
39 if len(values) == 2 and all(is_float(v) for v in values):
40 # Convert values to float and append to the respective lists
41 x_values.append(float(values[0]))
42 y_values.append(float(values[1]))
43
44 #return x_values, y_values
45
46
47def is_float(value):
48 try:
49 float(value)
50 return True
51 except ValueError:
52 return False
53
54if __name__ == '__main__':
55 import sys, os, argparse
56
57
61 parser = argparse.ArgumentParser(description="Parse file and extract x, y values and title.")
62
63 # Add argument for the input filename
64 parser.add_argument('filename', type=str, help='The path to the file to be parsed.')
65
66 # Parse the arguments
67 args = parser.parse_args()
68
69
70 try:
71 with open(args.filename, 'r') as file:
72 file_content = file.read()
73 parse_file_contents(file_content,args.filename.rstrip(".top"))
74
75 except FileNotFoundError:
76 print(f"File {args.filename} not found. Please provide a valid file.")
void print(char *figname, TCanvas *c1)
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177
is_float(value)
parse_file_contents(file_content, file_name)