-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_single_element.py
More file actions
120 lines (82 loc) · 3.17 KB
/
plot_single_element.py
File metadata and controls
120 lines (82 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# encoding: UTF-8
import sys
import os.path
import glob
import numpy as np
import matplotlib
from matplotlib.ticker import MultipleLocator
import pylab
# Take data files from folder specified by user
element = sys.argv[1]
folders = sys.argv[2:]
for folder in folders:
path = os.path.join(folder, "*.F*")
file_list = glob.glob(path)
# Take sample name from file name
sample_name = os.path.splitext(os.path.basename(file_list[0]))[0]
# Make a list with files ending with F11, F12, ...
matrix_elements = []
for item in file_list:
extension = os.path.splitext(item)[1][1:]
matrix_elements.append(extension)
# Define function that gets data from files
def get_data(n,folder):
return np.genfromtxt(os.path.join(folder, sample_name + '.') + str(n),
delimiter='\t',
dtype=None ,
usecols=(0, 1, 2),
names='deg, data, error')
#return deg, data = np.loadtxt(os.path.join(sub_path, folder, sample_name + '.') + str(n),
#delimiter='\t', usecols=(0, 1), unpack=True)
def split_name(name):
return name[0], name[1:]
#Plot function
def plot_element(name,folder,symbol,label):
data = get_data(element,folder)
if element == 'F12':
pylab.errorbar(data['deg'], -data['data'],
fmt='o', mfc='None', mec=symbol,
markersize = 4, yerr=data['error'],
ecolor=symbol, elinewidth=0.5,
capsize= 0, label=label)
pylab.plot((0,180), (0,0), '--', color='k', linewidth=0.5)
else:
pylab.errorbar(data['deg'], data['data'],
fmt='o', mfc='None', mec=symbol,
markersize = 4, yerr=data['error'],
ecolor=symbol, elinewidth=0.5,
capsize= 0, label=label)
xmin,xmax = pylab.xlim()
ymin,ymax = pylab.ylim()
if element == 'F11':
pylab.yscale('log')
elif element == 'F22':
pylab.ylim(ymin = 0)
pylab.ylim(ymax = 1.1)
pylab.gca().yaxis.set_minor_locator(MultipleLocator(0.1))
else:
pylab.ylim(ymin = 1.8*ymin)
pylab.ylim(ymax = 1.8*ymax)
pylab.gca().yaxis.set_minor_locator(MultipleLocator(0.1))
pylab.xticks([0, 45, 90, 135, 180])
pylab.gca().xaxis.set_minor_locator(MultipleLocator(15))
return xmax,ymax
##############################################
pylab.figure(figsize=(3, 3), dpi=400)
pylab.rc('text', usetex=True)
pylab.rc("font", size = 9)
symbol=['blue','green']
label=['488nm','520nm']
for number,(folder) in enumerate(folders):
xmax,ymax=plot_element(element,folder,symbol[number],label[number])
letter, number = split_name(element)
pylab.xlabel( " Scattering angle (degrees) " , fontsize =9)
if element == 'F11':
pylab.text(0.4*xmax, 0.2*ymax, r'$F_{{{0}}}$'.format(str(number)), fontsize=12)
elif element == 'F12':
pylab.text(0.4*xmax, 0.75*ymax, '-'+r'$F_{{{0}}}$'.format(str(number))+r'$\rm /\textit{$F$}_{11}$', fontsize=12)
else:
pylab.text(0.4*xmax, 0.75*ymax, r'$F_{{{0}}}$'.format(str(number))+r'$\rm /\textit{$F$}_{11}$', fontsize=12)
pylab.tight_layout()
pylab.legend(numpoints=1,frameon=False,prop={'size':6})
pylab.savefig(element + sample_name + '.eps', bbox_inches='tight', dpi=400)