回答編集履歴

1

修正方法

2019/11/05 04:35

投稿

hayataka2049
hayataka2049

スコア30933

test CHANGED
@@ -13,3 +13,73 @@
13
13
  z_list = np.array(z_list)
14
14
 
15
15
  ```
16
+
17
+
18
+
19
+ ```Python
20
+
21
+ import matplotlib.pyplot as plt # maplotlibのpyplotをpltという名前でimportする
22
+
23
+ import numpy as np
24
+
25
+
26
+
27
+ x_list=[] # x_listを定義 (空のリストを作成)
28
+
29
+ z_list=[] # z_listを定義
30
+
31
+
32
+
33
+ f=open(r'C:\Users\Administartor\Desktop\田村\python\真のデータ.txt') # プロットしたいデータが入っているファイルをr(読み込み) t(テキスト)モードで読み込む
34
+
35
+
36
+
37
+ ## データを読み込み,x_listとy_listに値を格納する
38
+
39
+ for line in f:
40
+
41
+ data = line[:-1].split(' ')
42
+
43
+ x_list.append(float(data[0]))
44
+
45
+ z_list.append(float(data[1]))
46
+
47
+
48
+
49
+ ### 描画する
50
+
51
+ x_list = np.array(x_list)
52
+
53
+ z_list = np.array(z_list)
54
+
55
+ np.savetxt("buta.txt", np.hstack([x_list.reshape(-1,1), z_list.reshape(-1,1)]), delimiter=",")
56
+
57
+
58
+
59
+ plt.plot(x_list, z_list) #プロットするためのデータ指定: ここではx軸にx_list,z軸にz_listを指定。折れ線グラフ
60
+
61
+ plt.plot(x_list, z_list,color='bLUE',linewidth=4.0) #赤色で出力.線の太さを4.0pt
62
+
63
+
64
+
65
+ plt.xlabel('X') # x軸のラベル
66
+
67
+ plt.ylabel('Z') # y軸のラベル
68
+
69
+ #plt.legend(loc='best') # legend
70
+
71
+
72
+
73
+ # その他,描画用オプション
74
+
75
+ plt.xticks(fontsize=10)
76
+
77
+ plt.yticks(fontsize=10)
78
+
79
+ plt.grid(True) #グラフの枠を作成
80
+
81
+
82
+
83
+ plt.show() # 描画結果を出力する。必ず書く。
84
+
85
+ ```