-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxs_plot.py
60 lines (49 loc) · 1.75 KB
/
xs_plot.py
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
import matplotlib.pyplot as plt
from matplotlib.ticker import ScalarFormatter
import numpy as np
from math import *
def xs_plot(energy, values, titles=[]):
n = len(energy) - 1
for i in range(0, len(values)):
values[i] = values[i][:n] + [values[i][n-1]]
values[i] = np.array(values[i])
font = {'family' : 'normal',
'weight' : 'bold',
'size' : 9}
plt.rc('font', family='serif')
fig = plt.figure(facecolor="white")
ax = fig.add_subplot(111)
ax.grid(which='both', linestyle="-", color="0.95")
ax.set_axisbelow(True)
for i in range(0, len(values)):
if len(titles) > 1:
ax.step(energy, values[i], lw=2, label=titles[i], color='C'+repr(i), where='pre', linewidth=1)
else:
ax.step(energy, values[i], lw=2, color='C'+repr(i), where='pre', linewidth=1)
if (n>1):
ax.legend(loc='lower left')
xlabel = ax.set_xlabel('energy ($eV$)')
ax.set_ylabel('cross section ($cm^{-1}$)')
ax.loglog()
min, max = ax.yaxis.get_data_interval()
min = np.min( values )
ticks = get_ticks( min, max )
ax.set_yticks(ticks, minor=True)
plt.yticks([])
min, max = ax.xaxis.get_data_interval()
ticks = get_ticks( min, max )
ax.set_xticks(ticks, minor=True)
plt.xticks([])
fig.set_size_inches(2*4.36,2*2.23)
plt.savefig('test.png',dpi=300, bbox_extra_artists=[xlabel], bbox_inches='tight')
plt.show()
def get_ticks(mini,maxi):
if mini == 0:
mini = 1
mini = 10**floor(log10(mini))
maxi = 10**ceil(log10(maxi))
a = [ np.linspace(mini,mini*10,10)[:-1] ]
while a[-1][0]*10 < maxi:
a.append(a[-1]*10)
a = np.array(a)
return np.append(a, a[-1][0]*10).flatten()