回答編集履歴

2

実行結果の追記

2016/09/19 22:41

投稿

cesolution
cesolution

スコア217

test CHANGED
@@ -99,3 +99,9 @@
99
99
  plt.show()
100
100
 
101
101
  ```
102
+
103
+
104
+
105
+ 4つ適当なテキストデータを置いて上記コードを実行した結果が以下になります。
106
+
107
+ ![イメージ説明](5ad26234398871f58b2929b4b92b803c.png)

1

if文でのスイッチを変更

2016/09/19 22:41

投稿

cesolution
cesolution

スコア217

test CHANGED
@@ -61,3 +61,41 @@
61
61
  ```
62
62
 
63
63
  もう少しスマートな方法が思いつきましたらご連絡させていただきます。
64
+
65
+
66
+
67
+ ↓以下に変更後のコードを記載します。(改行を表示するために、以下回答欄の編集で再記させていただきます。)
68
+
69
+
70
+
71
+ ```Python
72
+
73
+
74
+
75
+ for filename in os.listdir(target_dir):
76
+
77
+ path_in = os.path.join(target_dir, filename)
78
+
79
+ if not (os.path.isfile(path_in) and path_in.endswith('.txt')):
80
+
81
+ continue
82
+
83
+
84
+
85
+ fp = codecs.open(path_in, encoding='cp932', errors='ignore')
86
+
87
+ data = np.loadtxt(fp, comments='#' ,dtype='float' ,delimiter='\t' ,skiprows=1)
88
+
89
+
90
+
91
+ x_txt = data[:,0]
92
+
93
+ y_txt = data[:,3]
94
+
95
+ plt.plot(x_txt,y_txt)
96
+
97
+
98
+
99
+ plt.show()
100
+
101
+ ```