Repository navigation
Expand file tree
/
Copy pathplot_PDF_0rh_diff.py
More file actions
122 lines (83 loc) · 4.68 KB
/
Copy pathplot_PDF_0rh_diff.py
File metadata and controls
122 lines (83 loc) · 4.68 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
119
120
121
122
# -*- coding: utf-8 -*-
"""
Created on Sun Dec 13 18:00:08 2015
@author: hty
"""
from numpy import *
from matplotlib.pyplot import *
import sys
from matplotlib import gridspec
#import the target file
import noNano_rh0 as target
import peak_assign as pn
''' indicate the range of data plotted'''
data_interval = 9
data_files_1=target.Readfile()[1][0::data_interval]
name_of_the_plot=['%s h'%(array(target.peaks()[0][0::data_interval][i])) for i in range (shape(data_files_1)[0])]
interm_syn = [np.array(data_files_1[i].readlines()) for i in range (np.shape(data_files_1)[0])]
''' remember to set start line number here '''
interm1_syn =[ [str.split(interm_syn[j][i]) for i in range(141,np.shape(interm_syn[j])[0])] for j in range (np.shape(data_files_1)[0])]
interm2_syn= [[[float(interm1_syn[k][j][i]) for j in range (0,np.shape(interm1_syn[k])[0])]for i in range (2) ] for k in range (np.shape(data_files_1)[0])]
#find local max to denote the peak position
local_max = [(diff(sign(diff(interm2_syn[i][1]))) < 0).nonzero()[0] + 1 for i in range (shape(data_files_1)[0])]
local_min = [(diff(sign(diff((np.array(interm2_syn[i][1])-array(interm2_syn[0][1]))))) > 0).nonzero()[0] + 1 for i in range (shape(data_files_1)[0]-1)]
# mininums
peakPosition_min=[interm2_syn[0][0][local_min[1][7]]]
peakPosition=[interm2_syn[0][0][local_max[0][4]],interm2_syn[0][0][local_max[0][5]], interm2_syn[0][0][local_max[0][6]], 2.8 ,interm2_syn[0][0][local_max[0][7]], interm2_syn[0][0][local_max[0][8]],3.9,interm2_syn[0][0][local_max[0][9]],interm2_syn[0][0][local_max[0][10]]]
nameOfthePeak = ['Si-O','Al/Mg-O','Ca-O','O-O','Si-Si','Ca-Si','Ca-Ca','Si-O','Ca-O']
''
# do normalization
norm_factor_wrt_last_curve = [interm2_syn[-1][1][pn.find_local_max(interm2_syn)[0][0][4]]/interm2_syn[i][1][pn.find_local_max(interm2_syn)[0][i][4]] for i in range (shape(data_files_1)[0])]
norm_factor_wrt_first_curve = [interm2_syn[0][1][local_max[0][4]]/interm2_syn[i][1][local_max[i][4]] for i in range (shape(data_files_1)[0])]
# set style of the plot
style.use('classic')
#change font properties of the plots
font = {'family' : 'normal',
'weight' : 'normal',
'size' : 17}
matplotlib.rc('font', **font)
# start plotting
close("all")
gs = gridspec.GridSpec(2, 1,
height_ratios=[2,1]
)
# f, ax = subplots(nrows=2, ncols=1, sharex=True, figsize=(7,7))
f = figure(figsize=(8,8))
ax0 = subplot(gs[0])
[ax0.plot(interm2_syn[i][0],np.array(interm2_syn[i][1])*norm_factor_wrt_first_curve[i], alpha=1,label='%s'%(name_of_the_plot[i])) for i in range (np.shape(data_files_1)[0])]
# f, ax = subplots(figsize=(9,7))
# [ax.plot(interm2_syn[i][0],np.array(interm2_syn[i][1])*norm_factor_wrt_first_curve[i], alpha=1,label='%s'%(name_of_the_plot[i])) for i in range (np.shape(data_files_1)[0])]
#add vertical lines at the local max
# num_of_peak_showed = [0,2,5]
num_of_peak_showed = arange(9)
num_of_peak_showed = append(num_of_peak_showed, [-3, -2, -1])
lengthOftheLine = [0.91, 0.3, 0.7, 0.4, 0.6, 0.8, 0.6, 0.55, 0.6, 0.8, 0.8, 0.8]
[ax0.axvline(pn.find_local_max(interm2_syn)[1][i],ymin=0,ymax=lengthOftheLine[i],color='k') for i in num_of_peak_showed]
#add names of the peaks
position_y = [3.5, -0.5, 2 , 0, 1.5, 2.7, 1.5, 1, 1.5]
[text(pn.find_local_max(interm2_syn)[1][i],position_y[i], pn.name_of_the_peak(interm2_syn)[i],horizontalalignment='center',fontsize=14) for i in num_of_peak_showed]
#increase the freq of the ticks
locator_params(axis='x',tight=True,nbins=20)
grid(axis='x')
xlim (0.8,6)
# ylim (-4,9)
#ax.axhline(y=0, color='k')
ylabel('G(r)')
legend(loc=0, fontsize ='small',ncol=1,columnspacing=0.5, labelspacing=0, frameon = True)
'''difference plots'''
ax1 = subplot(gs[1])
mag_factor = 1
[ax1.plot(interm2_syn[i][0],(np.array(interm2_syn[i][1])*norm_factor_wrt_first_curve[i]-array(interm2_syn[0][1])), '--',linewidth=1.5,alpha=1,label='%s - %s'%(name_of_the_plot[i], name_of_the_plot[0])) for i in range (np.shape(data_files_1)[0])]
#difference plots
# [ax.plot(interm2_syn[i][0],(np.array(interm2_syn[i][1])*norm_factor_wrt_first_curve[i]-array(interm2_syn[0][1]))*5 + 6, '--', alpha=1,label='%s - %s'%(name_of_the_plot[i], name_of_the_plot[0])) for i in range (np.shape(data_files_1)[0])]
# [ax.plot(interm2_syn[i][0],(np.array(interm2_syn[i][1])-array(interm2_syn[0][1]))*5 + 10, '--', linewidth=1.5,alpha=1,label='%s - 0h no norm.'%(name_of_the_plot[i])) for i in range (np.shape(data_files_1)[0])]
locator_params(axis='x',tight=True,nbins=20)
grid(axis='x')
xlabel(r'r ($\AA$)')
xlim (0.8,6)
ylim(-0.4, 0.6)
# text(5,7.5,'x 5')
legend(loc=0, fontsize ='small',ncol=2,columnspacing=0.5, labelspacing=0, frameon = True)
draw()
f.show()
# f.savefig('/Users/hty/desktop/diff pdf %s.pdf'%(target.__name__))