-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_ltc.py
executable file
·210 lines (173 loc) · 6.7 KB
/
plot_ltc.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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env python3
# plotrta.py
#
# Simple script to visualize Thermal conductivity from *.kl files.
#
#
import numpy as np
import matplotlib as mpl
from matplotlib.gridspec import GridSpec
#try:
# mpl.use("Qt5agg")
#except:
# pass
mpl.use('Pdf')
import matplotlib.pyplot as plt
import argparse # 1. argparseをインポート
parser = argparse.ArgumentParser(description='ase wrapper ') # 2. パーサを作る
#
# 3. parser.add_argumentで受け取る引数を追加していく
parser.add_argument('arg1' , help='alamode *.kl files',nargs='+') # 必須の引数を追加
parser.add_argument('--tmin', help="minimum Temperature[K]", type=float, default="0.0") # オプション引数(指定しなくても良い引数)を追加(type=で型指定)
parser.add_argument('--tmax', help="maximum Temperature[K]", type=float, default="-1") # オプション引数(指定しなくても良い引数)を追加(type=で型指定)
parser.add_argument('--ymin', help="minimum LTC[W/mK]", type=float, default="0.0")
parser.add_argument('--ymax', help="maximum LTC[W/mK]", type=float, default="-1")
parser.add_argument('-l', '--log', help="set logscale for xy axis", default="no" )
parser.add_argument('-a', '--axis', help="axis which is ploted. ", default="mean" )
#
#
args = parser.parse_args() # 4. 引数を解析
#
# print('arg4='+args.arg4)
# font styles
mpl.rc('font', **{'family': 'Times New Roman', 'sans-serif': ['Helvetica']})
mpl.rc('xtick', labelsize=16)
mpl.rc('ytick', labelsize=16)
mpl.rc('axes', labelsize=16)
mpl.rc('lines', linewidth=1.5)
mpl.rc('legend', fontsize='small')
# line colors and styles
color = ['b', 'g', 'r', 'm', 'k', 'c', 'y', 'r']
lsty = ['-', '-', '-', '-', '--', '--', '--', '--']
# ファイルからデータを読み込み
def read_files(filenames):
# 格納するデータ
datas=[]
#
for i,name in enumerate(filenames):
datas.append(np.loadtxt(name))
return datas
# 指定されなかった場合のtmaxを決定する.
def decide_tmax(datas):
maxlist=[]
for i in range(len(datas)):
maxlist.append(np.max(datas[i][:,0]))
return np.max(maxlist)
# yのmaxminを取り出す.
# この時,tmin,tmaxの範囲でのymin/ymaxを知る必要がある.
def get_y_minmax(datas,tmin,tmax):
#
ymin = []
ymax = []
#
if plot_axis=="mean":
for i in range(len(datas)):
# まず,tmin,tmaxに応じたdatasのindexを取得
min_indx=np.where(datas[i][:,0]>=tmin)[0][0]
max_indx=np.where(datas[i][:,0]<=tmax)[0][-1]
# print("tminより大きい要素", np.where(datas[i][:,0]>=tmin)[0][0]) #条件を満たす最初の要素
# print("tmaxより小さい要素", np.where(datas[i][:,0]<=tmax)[0][-1]) #条件を満たす最後の要素
#
ymin.append(np.min((datas[i][min_indx:max_indx,1]+datas[i][min_indx:max_indx,5]+datas[i][min_indx:max_indx,9])/3))
ymax.append(np.max((datas[i][min_indx:max_indx,1]+datas[i][min_indx:max_indx,5]+datas[i][min_indx:max_indx,9])/3))
# 最終的に最小最大を出す
ymin=np.min(np.array(ymin))
ymax=np.max(np.array(ymax))*1.1 # 1.1倍下駄を履かせておく
return ymin, ymax
# plotする
def run_plot(datas,tmin,tmax,ymin,ymax):
# tmaxの指定
if tmax==-1:
print(" ")
print(" WARNING : tmax is not specified. ")
print(" Use maximum values in *.kl ")
print(" ")
tmax=decide_tmax(datas)
# ymaxの指定
if ymax==-1:
print(" ")
print(" WARNING : ymax is not specified. ")
print(" Automatic decision of ymax is used ")
print(" ")
ymin, ymax = get_y_minmax(datas,tmin,tmax)
# datasにある複数のデータをプロットする,
fig, ax = plt.subplots()
ax.set_xlim(tmin,tmax) # plot range[K]
ax.set_ylim(ymin,ymax) # plot range[K]
# これはなんだ?
# gs = GridSpec(nrows=1, ncols=nax )
# gs.update(wspace=0.1)
#
# 複数データのプロット
for i in range(len(datas)):
# ax = plt.subplot(gs[iax])
#
if plot_axis == "mean":
ax.plot(datas[i][:,0], (datas[i][:,1]+datas[i][:,5]+datas[i][:,9])/3,linestyle=lsty[i], color=color[i], label=filenames[i])
#
# 初めのデータの時にcaptionをつける
if i == 0:
ax.set_ylabel("LTC (W/mK)", labelpad=10)
ax.set_xlabel("Temp (K)", labelpad=10)
# else:
# ax.set_yticklabels([])
# ax.set_yticks([])
#
# plt.axis([xmin_ax[iax], xmax_ax[iax], ymin, ymax])
# ax.set_xticks(xticks_ax[iax])
# ax.set_xticklabels(xticklabels_ax[iax])
# ax.xaxis.grid(True, linestyle='-')
#if options.print_key and iax == 0:
# ax.legend(loc='best', prop={'size': 10})
ax.legend(loc='best', prop={'size': 10})
# plt.tight_layout()
# https://www.delftstack.com/ja/howto/matplotlib/save-figures-identical-to-displayed-figures-matplotlib/
plt.savefig("ltc.pdf", bbox_inches='tight')
plt.show()
if __name__ == '__main__':
'''
For details of available options, please type
$ python plot_ltc.py -h
'''
#
print("*****************************************************************")
print(" plot_ltc.py ")
print(" Version. 0.0.1 ")
print("*****************************************************************")
print("")
#
args = parser.parse_args() # 4. 引数を解析
filenames = args.arg1
tmin = args.tmin
tmax = args.tmax
ymin = args.ymin
ymax = args.ymax
plot_axis = args.axis
if len(filenames) == 0:
print("Usage: plotband.py [options] file1.bands file2.bands ...")
print("For details of available options, please type\n$ python plotband.py -h")
exit(1)
else:
print(" ## ====")
print(" Number of files = %d" % len(filenames))
print(" ")
#
if plot_axis == "mean":
print(" ## ====")
print(" axis=mean :: We plot (k_xx+k_yy+k_zz)/3 " )
print(" ")
# read *.kl
datas=read_files(filenames)
#
#
# decide ymin, ymax
if ymax==-1:
ymin, ymax = get_y_minmax(datas,tmin,tmax)
# plot datas
# とりあえずyminは0で固定
run_plot(datas,tmin,tmax, 0, ymax)
#nax, xticks_ax, xticklabels_ax, xmin_ax, xmax_ax, ymin, ymax, \
# data_merged_ax = preprocess_data(
# files, options.unitname, options.normalize_xaxis)
#run_plot(nax, xticks_ax, xticklabels_ax,
# xmin_ax, xmax_ax, ymin, ymax, data_merged_ax)