teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

4

修正

2020/03/10 07:30

投稿

tiitoi
tiitoi

スコア21960

answer CHANGED
@@ -164,4 +164,69 @@
164
164
  axes.view_init(30, -45)
165
165
  ```
166
166
 
167
- ![イメージ説明](3b353b86a9fee12899cf139702078fe9.png)
167
+ ![イメージ説明](3b353b86a9fee12899cf139702078fe9.png)
168
+
169
+ ## 追記
170
+
171
+ ```python
172
+ import numpy as np
173
+ import matplotlib.pyplot as plt
174
+ from mpl_toolkits.mplot3d import Axes3D
175
+
176
+
177
+ sensordata = np.array(
178
+ [
179
+ [20.75, 21.25, 22.25, 22.5, 21.25, 21.25, 22.75, 23.25],
180
+ [20.5, 21.0, 22.25, 22.25, 23.25, 23.25, 24.0, 24.75],
181
+ [20.0, 21.25, 21.75, 22.0, 22.5, 23.75, 25.5, 25.25],
182
+ [20.0, 19.75, 20.75, 22.5, 24.25, 24.75, 25.25, 26.0],
183
+ [20.25, 22.25, 23.25, 24.25, 24.0, 24.5, 25.5, 25.75],
184
+ [21.0, 20.75, 21.0, 20.75, 21.5, 24.75, 26.0, 23.5],
185
+ [21.0, 20.0, 20.25, 22.5, 24.0, 24.75, 22.25, 23.75],
186
+ [21.25, 18.5, 20.5, 22.5, 21.0, 20.5, 20.25, 21.75],
187
+ ]
188
+ )
189
+
190
+ # 点を表示する (x, y) 座標を作成
191
+ X, Y = np.indices(sensordata.shape)
192
+
193
+ # 描画する。
194
+ fig = plt.figure(figsize=(7, 7))
195
+ axes = fig.add_subplot(111, projection="3d")
196
+ points = axes.scatter(
197
+ X.flat,
198
+ Y.flat,
199
+ sensordata.flat,
200
+ c=sensordata.flat,
201
+ cmap="jet",
202
+ edgecolor="gray",
203
+ s=50,
204
+ )
205
+ axes.plot_surface(X, Y, sensordata, cmap="jet", alpha=0.4)
206
+
207
+ # カラーバー追加 (xmin, ymin, w, h) でカラーバーを表示する位置を指定
208
+ cbar_ax = fig.add_axes((0.9, 0.3, 0.02, 0.4))
209
+ cbar = fig.colorbar(points, cax=cbar_ax)
210
+ cbar.set_label("Temp")
211
+
212
+ # 軸ラベル設定
213
+ axes.set_xlabel("X")
214
+ axes.set_ylabel("Y")
215
+
216
+ # 軸目盛設定
217
+ axes.set_xticks(np.arange(0, 9, 1))
218
+ axes.set_yticks(np.arange(0, 9, 1))
219
+ axes.set_zticks((10, 20, 30))
220
+
221
+ # Title表示
222
+ axes.set_title("Temp", fontsize=16)
223
+
224
+ # 余白調整
225
+ plt.subplots_adjust(right=0.85)
226
+ plt.subplots_adjust(wspace=0.15)
227
+
228
+ # 視点
229
+ axes.view_init(30, -45)
230
+ ```
231
+
232
+ ![イメージ説明](35ccddc0262882bf3b091a8a912bff54.png)

3

修正

2020/03/10 07:30

投稿

tiitoi
tiitoi

スコア21960

answer CHANGED
@@ -90,4 +90,78 @@
90
90
  plt.show()
91
91
  ```
92
92
 
93
- ![イメージ説明](ca4820a2b52c0b31bb8e6d604b463984.png)
93
+ ![イメージ説明](ca4820a2b52c0b31bb8e6d604b463984.png)
94
+
95
+ ## 追記
96
+
97
+ > 私も試してみましたが、上下にグレーの線がでてしまいます。
98
+
99
+ こちらで確認しましたが、グレーの線が出る現象は再現しません。
100
+ 当方のバージョンは 3.1.3 です。
101
+
102
+ ```python
103
+ import matplotlib
104
+ print(matplotlib.__version__) # 3.1.3
105
+ ```
106
+
107
+ ```python
108
+ import numpy as np
109
+ import matplotlib.pyplot as plt
110
+ from mpl_toolkits.mplot3d import Axes3D
111
+
112
+
113
+ sensordata = np.array(
114
+ [
115
+ [20.75, 21.25, 22.25, 22.5, 21.25, 21.25, 22.75, 23.25],
116
+ [20.5, 21.0, 22.25, 22.25, 23.25, 23.25, 24.0, 24.75],
117
+ [20.0, 21.25, 21.75, 22.0, 22.5, 23.75, 25.5, 25.25],
118
+ [20.0, 19.75, 20.75, 22.5, 24.25, 24.75, 25.25, 26.0],
119
+ [20.25, 22.25, 23.25, 24.25, 24.0, 24.5, 25.5, 25.75],
120
+ [21.0, 20.75, 21.0, 20.75, 21.5, 24.75, 26.0, 23.5],
121
+ [21.0, 20.0, 20.25, 22.5, 24.0, 24.75, 22.25, 23.75],
122
+ [21.25, 18.5, 20.5, 22.5, 21.0, 20.5, 20.25, 21.75],
123
+ ]
124
+ )
125
+
126
+ # 点を表示する (x, y) 座標を作成
127
+ X, Y = np.indices(sensordata.shape)
128
+
129
+ # 描画する。
130
+ fig = plt.figure(figsize=(7, 7))
131
+ axes = fig.add_subplot(111, projection="3d")
132
+ points = axes.scatter(
133
+ X.flat,
134
+ Y.flat,
135
+ sensordata.flat,
136
+ c=sensordata.flat,
137
+ cmap="jet",
138
+ edgecolor="gray",
139
+ s=50,
140
+ )
141
+
142
+ # カラーバー追加 (xmin, ymin, w, h) でカラーバーを表示する位置を指定
143
+ cbar_ax = fig.add_axes((0.9, 0.3, 0.02, 0.4))
144
+ cbar = fig.colorbar(points, cax=cbar_ax)
145
+ cbar.set_label("Temp")
146
+
147
+ # 軸ラベル設定
148
+ axes.set_xlabel("X")
149
+ axes.set_ylabel("Y")
150
+
151
+ # 軸目盛設定
152
+ axes.set_xticks(np.arange(0, 9, 1))
153
+ axes.set_yticks(np.arange(0, 9, 1))
154
+ axes.set_zticks((10, 20, 30))
155
+
156
+ # Title表示
157
+ axes.set_title("Temp", fontsize=16)
158
+
159
+ # 余白調整
160
+ plt.subplots_adjust(right=0.85)
161
+ plt.subplots_adjust(wspace=0.15)
162
+
163
+ # 視点
164
+ axes.view_init(30, -45)
165
+ ```
166
+
167
+ ![イメージ説明](3b353b86a9fee12899cf139702078fe9.png)

2

修正

2020/03/10 06:57

投稿

tiitoi
tiitoi

スコア21960

answer CHANGED
@@ -70,6 +70,8 @@
70
70
  [21.25, 18.5, 20.5, 22.5, 21.0, 20.5, 20.25, 21.75],
71
71
  ]
72
72
  )
73
+
74
+ # 点を表示する (x, y) 座標を作成
73
75
  X, Y = np.indices(data.shape)
74
76
 
75
77
  # 描画する。

1

修正d

2020/03/10 06:31

投稿

tiitoi
tiitoi

スコア21960

answer CHANGED
@@ -48,4 +48,44 @@
48
48
  plt.show()
49
49
  ```
50
50
 
51
- ![イメージ説明](87c5a9257e10bc6391c8fc21a016e1d1.png)
51
+ ![イメージ説明](87c5a9257e10bc6391c8fc21a016e1d1.png)
52
+
53
+ ## 追記
54
+
55
+ ```python
56
+ import numpy as np
57
+ import matplotlib.pyplot as plt
58
+ from mpl_toolkits.mplot3d import Axes3D
59
+
60
+
61
+ data = np.array(
62
+ [
63
+ [20.75, 21.25, 22.25, 22.5, 21.25, 21.25, 22.75, 23.25],
64
+ [20.5, 21.0, 22.25, 22.25, 23.25, 23.25, 24.0, 24.75],
65
+ [20.0, 21.25, 21.75, 22.0, 22.5, 23.75, 25.5, 25.25],
66
+ [20.0, 19.75, 20.75, 22.5, 24.25, 24.75, 25.25, 26.0],
67
+ [20.25, 22.25, 23.25, 24.25, 24.0, 24.5, 25.5, 25.75],
68
+ [21.0, 20.75, 21.0, 20.75, 21.5, 24.75, 26.0, 23.5],
69
+ [21.0, 20.0, 20.25, 22.5, 24.0, 24.75, 22.25, 23.75],
70
+ [21.25, 18.5, 20.5, 22.5, 21.0, 20.5, 20.25, 21.75],
71
+ ]
72
+ )
73
+ X, Y = np.indices(data.shape)
74
+
75
+ # 描画する。
76
+ fig = plt.figure(figsize=(7, 7))
77
+ ax = fig.add_subplot(111, projection="3d")
78
+ ax.set_zticks((10, 20, 30))
79
+ ax.view_init(30, -45)
80
+ points = ax.scatter(
81
+ X.flat, Y.flat, data.flat, c=data.flat, cmap="jet", edgecolor="gray", s=50
82
+ )
83
+
84
+ # カラーバー追加 (xmin, ymin, w, h) でカラーバーを表示する位置を指定
85
+ cax = fig.add_axes((0.9, 0.3, 0.02, 0.4))
86
+ fig.colorbar(points, cax=cax)
87
+
88
+ plt.show()
89
+ ```
90
+
91
+ ![イメージ説明](ca4820a2b52c0b31bb8e6d604b463984.png)