-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.py
executable file
·42 lines (34 loc) · 1.15 KB
/
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
import numpy as np
import matplotlib.pyplot as plt
import fire
def loadText(filename,c):
with open(filename,"r") as f:
return np.array([float(line.split(",")[c]) for line in f.readlines()])
class csvplot:
def plot(self,input_file, output_file = "output.png",xc = 0,yc = 1,
fontsize = 18, xlabel = "x-axis", ylabel = "y-axis", color = "k",
xmax = float("nan"), xmin = float("nan"), ymax = float("nan"), ymin = float("nan")):
# load
y = loadText(input_file,yc)
x = loadText(input_file,xc)
plt.plot(x,y,'k')
# 軸ラベル
plt.xlabel(xlabel, fontsize = fontsize)
plt.ylabel(ylabel, fontsize = fontsize)
# 最大最小
if xmax != xmax:
xmax = float(len(x))
if xmin != xmin:
xmin = 0
if ymax != ymax:
ymax = max(y)
if ymin != ymin:
ymin = min(y)
plt.xlim(xmax = xmax, xmin = xmin)
plt.ylim(ymax = ymax, ymin = ymin)
# いい感じに調整
plt.tight_layout()
# 出力
plt.savefig(output_file)
if __name__ == '__main__':
fire.Fire(csvplot)