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

質問編集履歴

6

情報更新

2020/03/17 07:43

投稿

raspypy
raspypy

スコア247

title CHANGED
File without changes
body CHANGED
@@ -1,85 +1,8 @@
1
1
  ##やろうとしていること
2
2
 
3
3
  Matplotlibで作成した画像を結合させたい。
4
- **1つめのグラフ画像**
5
- ![イメージ説明](43722658051ebb74156e846923ac2301.png)
4
+ 2つのグラフを1つの図に作成するプログラムを作っています。
6
5
 
7
- **2つめのグラフ画像**
8
- ![イメージ説明](dfdcee5cc2bc25fe0c7df8313f22d333.png)
9
-
10
- この2つのグラフを1つの図に作成するプログラムを作っています。
11
-
12
- ##プログラムコード
13
-
14
- ```python
15
- # データ取得
16
- sensordata = np.array(linedata)
17
-
18
- #fig = plt.figure()
19
- fig, axes = plt.subplots(figsize=(10,4),ncols=2)
20
-
21
- im1 = axes[0].imshow(sensordata, cmap="plasma",
22
- extent=[0,sensordata.shape[0],0,sensordata.shape[1]],
23
- interpolation="bicubic",
24
- aspect='auto',
25
- origin='lower')
26
-
27
- #軸ラベル設定
28
- axes[0].set_xlabel("X")
29
- axes[0].set_ylabel("Y")
30
-
31
- #軸目盛設定(設定方法を2つ記載)
32
- axes[0].set_xticks(np.arange(0, 9, 1))
33
- axes[0].set_yticks(np.arange(0, 9, 1))
34
- #im1 ColorBar設定
35
- cbar1 = fig.colorbar(im1, ax=axes[0])
36
- cbar1.set_label("Temp")
37
-
38
- X, Y = np.indices(sensordata.shape)
39
-
40
- # 描画する。
41
- axes[1] = fig.add_subplot(122, projection="3d")
42
-
43
- #散布図(dot)表示
44
- #s: Scale Default20
45
- im2 = axes[1].scatter(
46
- X.flat,
47
- Y.flat,
48
- sensordata.flat,
49
- c=sensordata.flat,
50
- cmap="jet",
51
- edgecolor="gray",
52
- s=160,
53
- )
54
-
55
- #面表示 alphaで透過設定
56
- axes[1].plot_surface(X, Y, sensordata, cmap="jet", alpha=0.4)
57
-
58
- # カラーバー追加 (xmin, ymin, w, h) でカラーバーを表示する位置を指定
59
- cbar2 = fig.colorbar(im2, ax=axes[1])
60
- cbar2.set_label("Temp")
61
-
62
- #軸ラベル設定
63
- axes[1].set_xlabel("X")
64
- axes[1].set_ylabel("Y")
65
-
66
- #軸目盛設定
67
- temp_min = sensordata.min()
68
- temp_max = sensordata.max()
69
- axes[1].set_xticks(np.arange(0, 9, 1))
70
- axes[1].set_yticks(np.arange(0, 9, 1))
71
- axes[1].set_zticks(np.arange(temp_min, temp_max, 1))
72
-
73
- #余白調整
74
- plt.subplots_adjust(right=0.85)
75
- plt.subplots_adjust(wspace=0.15)
76
- plt.savefig('/home/pi/dev/data/thermo/bicubic_3D.png', format='png')
77
- ```
78
-
79
6
  ##困っていること
80
7
  プログラムを実行すると、次のような表示になってしまいます。
81
- 右画像の周辺に枠(X, Yとも0~1の範囲)ができてしまいます。
8
+ 右画像の周辺に枠(X, Yとも0~1の範囲)ができてしまいます。
82
- ![イメージ説明](c17f6a30bec93bbc80eef1a52d5fbb0b.png)
83
-
84
- **画像追加**
85
- ![イメージ説明](3e18d4477f08d36352ccac88ceb3358c.png)

5

画像を追加しました。

2020/03/17 07:43

投稿

raspypy
raspypy

スコア247

title CHANGED
File without changes
body CHANGED
@@ -79,4 +79,7 @@
79
79
  ##困っていること
80
80
  プログラムを実行すると、次のような表示になってしまいます。
81
81
  右画像の周辺に枠(X, Yとも0~1の範囲)ができてしまいます。
82
- ![イメージ説明](c17f6a30bec93bbc80eef1a52d5fbb0b.png)
82
+ ![イメージ説明](c17f6a30bec93bbc80eef1a52d5fbb0b.png)
83
+
84
+ **画像追加**
85
+ ![イメージ説明](3e18d4477f08d36352ccac88ceb3358c.png)

4

最新の情報に更新

2020/03/11 04:52

投稿

raspypy
raspypy

スコア247

title CHANGED
File without changes
body CHANGED
@@ -15,43 +15,34 @@
15
15
  # データ取得
16
16
  sensordata = np.array(linedata)
17
17
 
18
- fig = plt.figure()
18
+ #fig = plt.figure()
19
- axes1 = fig.add_subplot(1, 2, 1)
20
- axes2 = fig.add_subplot(1, 2, 2)
19
+ fig, axes = plt.subplots(figsize=(10,4),ncols=2)
21
20
 
22
- im1 = axes1.imshow(sensordata, cmap="plasma",
21
+ im1 = axes[0].imshow(sensordata, cmap="plasma",
23
22
  extent=[0,sensordata.shape[0],0,sensordata.shape[1]],
24
23
  interpolation="bicubic",
25
24
  aspect='auto',
26
25
  origin='lower')
27
26
 
28
27
  #軸ラベル設定
29
- axes1.set_xlabel("X")
28
+ axes[0].set_xlabel("X")
30
- axes1.set_ylabel("Y")
29
+ axes[0].set_ylabel("Y")
31
30
 
32
31
  #軸目盛設定(設定方法を2つ記載)
33
- axes1.set_xticks(np.arange(0, 9, 1))
32
+ axes[0].set_xticks(np.arange(0, 9, 1))
34
- axes1.set_yticks(np.arange(0, 9, 1))
33
+ axes[0].set_yticks(np.arange(0, 9, 1))
34
+ #im1 ColorBar設定
35
+ cbar1 = fig.colorbar(im1, ax=axes[0])
36
+ cbar1.set_label("Temp")
35
37
 
36
- axpos = axes1.get_position()
37
- #Color Bar作成
38
- #add_axes([x軸の開始位置, y軸の開始位置, x軸の長さ(全体に対する比率), y軸の長さ(全体に対する比率)])
39
- cbar_ax = fig.add_axes([0.5, axpos.y0, 0.02, axpos.height])
40
- cbar = fig.colorbar(im1,cax=cbar_ax)
41
- cbar.set_label("Temp")
42
- #Title表示
43
- axes1.set_title(title, fontsize=12)
44
-
45
- temp_min = sensordata.min()
46
- temp_max = sensordata.max()
47
38
  X, Y = np.indices(sensordata.shape)
48
39
 
49
40
  # 描画する。
50
- axes2 = fig.add_subplot(122, projection="3d")
41
+ axes[1] = fig.add_subplot(122, projection="3d")
51
42
 
52
43
  #散布図(dot)表示
53
44
  #s: Scale Default20
54
- im2 = axes2.scatter(
45
+ im2 = axes[1].scatter(
55
46
  X.flat,
56
47
  Y.flat,
57
48
  sensordata.flat,
@@ -60,22 +51,24 @@
60
51
  edgecolor="gray",
61
52
  s=160,
62
53
  )
54
+
55
+ #面表示 alphaで透過設定
63
- axes2.plot_surface(X, Y, sensordata, cmap="jet", alpha=0.4)
56
+ axes[1].plot_surface(X, Y, sensordata, cmap="jet", alpha=0.4)
57
+
64
58
  # カラーバー追加 (xmin, ymin, w, h) でカラーバーを表示する位置を指定
65
- cbar_ax = fig.add_axes((0.9, 0.3, 0.02, 0.4))
66
- cbar = fig.colorbar(im2, cax=cbar_ax)
59
+ cbar2 = fig.colorbar(im2, ax=axes[1])
67
- cbar.set_label("Temp")
60
+ cbar2.set_label("Temp")
61
+
68
62
  #軸ラベル設定
69
- axes2.set_xlabel("X")
63
+ axes[1].set_xlabel("X")
70
- axes2.set_ylabel("Y")
64
+ axes[1].set_ylabel("Y")
65
+
71
66
  #軸目盛設定
67
+ temp_min = sensordata.min()
68
+ temp_max = sensordata.max()
72
- axes2.set_xticks(np.arange(0, 9, 1))
69
+ axes[1].set_xticks(np.arange(0, 9, 1))
73
- axes2.set_yticks(np.arange(0, 9, 1))
70
+ axes[1].set_yticks(np.arange(0, 9, 1))
74
- axes2.set_zticks(np.arange(temp_min, temp_max, 1))
71
+ axes[1].set_zticks(np.arange(temp_min, temp_max, 1))
75
- #Title表示
76
- axes2.set_title(title, fontsize=12)
77
- # 視点
78
- axes2.view_init(30, -45)
79
72
 
80
73
  #余白調整
81
74
  plt.subplots_adjust(right=0.85)
@@ -85,12 +78,5 @@
85
78
 
86
79
  ##困っていること
87
80
  プログラムを実行すると、次のような表示になってしまいます。
88
- 左側画像(bicubic)カラーバー重なってしまいます。
89
- 右側画像と左側画像、それぞれのカラバーの大きさを合わせたいと考えています。
90
- ![イメージ説明](c6c41c5dcb19a54881d5673710c333c5.png)
91
-
92
- このプログラムを実行すると、次のワーニングが表示されてしまいます。
93
- ```text
94
- /home/pi/.local/lib/python2.7/site-packages/matplotlib/cbook/deprecation.py:107: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
95
- warnings.warn(message, mplDeprecation, stacklevel=1)
96
- ```
81
+ 画像の周辺に枠(X, Yとも0~1の範囲)できてしまいます。
82
+ ![イメジ説明](c17f6a30bec93bbc80eef1a52d5fbb0b.png)

3

ワーニング情報を更新しました。

2020/03/11 04:15

投稿

raspypy
raspypy

スコア247

title CHANGED
File without changes
body CHANGED
@@ -15,40 +15,43 @@
15
15
  # データ取得
16
16
  sensordata = np.array(linedata)
17
17
 
18
+ fig = plt.figure()
19
+ axes1 = fig.add_subplot(1, 2, 1)
18
- fig, axes = plt.subplots(figsize=(8,4),ncols=2)
20
+ axes2 = fig.add_subplot(1, 2, 2)
21
+
19
- im1 = axes[1].imshow(sensordata, cmap="plasma",
22
+ im1 = axes1.imshow(sensordata, cmap="plasma",
20
23
  extent=[0,sensordata.shape[0],0,sensordata.shape[1]],
21
24
  interpolation="bicubic",
22
25
  aspect='auto',
23
26
  origin='lower')
24
27
 
25
28
  #軸ラベル設定
26
- axes[0].set_xlabel("X")
29
+ axes1.set_xlabel("X")
27
- axes[0].set_ylabel("Y")
30
+ axes1.set_ylabel("Y")
28
31
 
29
32
  #軸目盛設定(設定方法を2つ記載)
30
- axes[0].set_xticks(np.arange(0, 9, 1))
33
+ axes1.set_xticks(np.arange(0, 9, 1))
31
- axes[0].set_yticks(np.arange(0, 9, 1))
34
+ axes1.set_yticks(np.arange(0, 9, 1))
32
35
 
33
- axpos = axes[0].get_position()
36
+ axpos = axes1.get_position()
34
37
  #Color Bar作成
35
38
  #add_axes([x軸の開始位置, y軸の開始位置, x軸の長さ(全体に対する比率), y軸の長さ(全体に対する比率)])
36
- cbar_ax = fig.add_axes([0.87, axpos.y0, 0.02, axpos.height])
39
+ cbar_ax = fig.add_axes([0.5, axpos.y0, 0.02, axpos.height])
37
40
  cbar = fig.colorbar(im1,cax=cbar_ax)
38
41
  cbar.set_label("Temp")
42
+ #Title表示
43
+ axes1.set_title(title, fontsize=12)
39
44
 
40
-
41
-
42
45
  temp_min = sensordata.min()
43
46
  temp_max = sensordata.max()
44
47
  X, Y = np.indices(sensordata.shape)
45
48
 
46
49
  # 描画する。
47
- axes[1] = fig.add_subplot(111, projection="3d")
50
+ axes2 = fig.add_subplot(122, projection="3d")
48
51
 
49
52
  #散布図(dot)表示
50
53
  #s: Scale Default20
51
- points = axes[1].scatter(
54
+ im2 = axes2.scatter(
52
55
  X.flat,
53
56
  Y.flat,
54
57
  sensordata.flat,
@@ -57,31 +60,22 @@
57
60
  edgecolor="gray",
58
61
  s=160,
59
62
  )
60
- axes[1].plot_surface(X, Y, sensordata, cmap="jet", alpha=0.4)
63
+ axes2.plot_surface(X, Y, sensordata, cmap="jet", alpha=0.4)
61
-
62
64
  # カラーバー追加 (xmin, ymin, w, h) でカラーバーを表示する位置を指定
63
65
  cbar_ax = fig.add_axes((0.9, 0.3, 0.02, 0.4))
64
- cbar = fig.colorbar(points, cax=cbar_ax)
66
+ cbar = fig.colorbar(im2, cax=cbar_ax)
65
67
  cbar.set_label("Temp")
66
-
67
68
  #軸ラベル設定
68
- axes[1].set_xlabel("X")
69
+ axes2.set_xlabel("X")
69
- axes[1].set_ylabel("Y")
70
+ axes2.set_ylabel("Y")
70
-
71
71
  #軸目盛設定
72
- axes[1].set_xticks(np.arange(0, 9, 1))
72
+ axes2.set_xticks(np.arange(0, 9, 1))
73
- axes[1].set_yticks(np.arange(0, 9, 1))
73
+ axes2.set_yticks(np.arange(0, 9, 1))
74
- axes[1].set_zticks(np.arange(temp_min, temp_max, 1))
74
+ axes2.set_zticks(np.arange(temp_min, temp_max, 1))
75
-
76
75
  #Title表示
77
- axes[1].set_title(title, fontsize=16)
76
+ axes2.set_title(title, fontsize=12)
78
-
79
- #余白調整
80
- plt.subplots_adjust(right=0.85)
81
- plt.subplots_adjust(wspace=0.15)
82
-
83
77
  # 視点
84
- axes[1].view_init(30, -45)
78
+ axes2.view_init(30, -45)
85
79
 
86
80
  #余白調整
87
81
  plt.subplots_adjust(right=0.85)
@@ -91,4 +85,12 @@
91
85
 
92
86
  ##困っていること
93
87
  プログラムを実行すると、次のような表示になってしまいます。
94
- ![イメージ説明](6f0b4ccefd8f19c67beedb52a7e06174.png)
88
+ 左側画像(bicubic)のカラーバーが重なってしまいます。
89
+ 右側画像と左側画像、それぞれのカラーバーの大きさを合わせたいと考えています。
90
+ ![イメージ説明](c6c41c5dcb19a54881d5673710c333c5.png)
91
+
92
+ このプログラムを実行すると、次のワーニングが表示されてしまいます。
93
+ ```text
94
+ /home/pi/.local/lib/python2.7/site-packages/matplotlib/cbook/deprecation.py:107: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
95
+ warnings.warn(message, mplDeprecation, stacklevel=1)
96
+ ```

2

質問の内容を更新しました。

2020/03/11 02:33

投稿

raspypy
raspypy

スコア247

title CHANGED
File without changes
body CHANGED
@@ -1,37 +1,94 @@
1
1
  ##やろうとしていること
2
2
 
3
3
  Matplotlibで作成した画像を結合させたい。
4
+ **1つめのグラフ画像**
5
+ ![イメージ説明](43722658051ebb74156e846923ac2301.png)
4
6
 
7
+ **2つめのグラフ画像**
8
+ ![イメージ説明](dfdcee5cc2bc25fe0c7df8313f22d333.png)
9
+
10
+ この2つのグラフを1つの図に作成するプログラムを作っています。
11
+
5
12
  ##プログラムコード
6
- **1.pngと2.pngの画像が保存されていることまで確認済です。**
13
+
7
14
  ```python
15
+ # データ取得
8
- def drawing1():
16
+ sensordata = np.array(linedata)
9
- #省略
10
- global im1
11
- im1 = plt.savefig('/home/pi/1.png', format='png')
12
17
 
13
- def drawing2():
18
+ fig, axes = plt.subplots(figsize=(8,4),ncols=2)
14
- #省略
15
- global im2
16
- im2 = plt.savefig('/home/pi/2.png', format='png')
19
+ im1 = axes[1].imshow(sensordata, cmap="plasma",
20
+ extent=[0,sensordata.shape[0],0,sensordata.shape[1]],
21
+ interpolation="bicubic",
22
+ aspect='auto',
23
+ origin='lower')
17
24
 
25
+ #軸ラベル設定
18
- if __name__ == '__main__':
26
+ axes[0].set_xlabel("X")
19
- try:
20
- drawing1()
27
+ axes[0].set_ylabel("Y")
28
+
21
- drawing2()
29
+ #軸目盛設定(設定方法を2つ記載)
22
- print ('Heat Mapping Generated...')
30
+ axes[0].set_xticks(np.arange(0, 9, 1))
31
+ axes[0].set_yticks(np.arange(0, 9, 1))
32
+
33
+ axpos = axes[0].get_position()
34
+ #Color Bar作成
35
+ #add_axes([x軸の開始位置, y軸の開始位置, x軸の長さ(全体に対する比率), y軸の長さ(全体に対する比率)])
36
+ cbar_ax = fig.add_axes([0.87, axpos.y0, 0.02, axpos.height])
23
- im_h = cv2.hconcat([im1, im2])
37
+ cbar = fig.colorbar(im1,cax=cbar_ax)
38
+ cbar.set_label("Temp")
39
+
40
+
41
+
42
+ temp_min = sensordata.min()
43
+ temp_max = sensordata.max()
44
+ X, Y = np.indices(sensordata.shape)
45
+
46
+ # 描画する。
47
+ axes[1] = fig.add_subplot(111, projection="3d")
48
+
49
+ #散布図(dot)表示
50
+ #s: Scale Default20
51
+ points = axes[1].scatter(
52
+ X.flat,
53
+ Y.flat,
54
+ sensordata.flat,
55
+ c=sensordata.flat,
56
+ cmap="jet",
57
+ edgecolor="gray",
58
+ s=160,
59
+ )
60
+ axes[1].plot_surface(X, Y, sensordata, cmap="jet", alpha=0.4)
61
+
62
+ # カラーバー追加 (xmin, ymin, w, h) でカラーバーを表示する位置を指定
63
+ cbar_ax = fig.add_axes((0.9, 0.3, 0.02, 0.4))
64
+ cbar = fig.colorbar(points, cax=cbar_ax)
65
+ cbar.set_label("Temp")
66
+
67
+ #軸ラベル設定
68
+ axes[1].set_xlabel("X")
69
+ axes[1].set_ylabel("Y")
70
+
71
+ #軸目盛設定
72
+ axes[1].set_xticks(np.arange(0, 9, 1))
73
+ axes[1].set_yticks(np.arange(0, 9, 1))
74
+ axes[1].set_zticks(np.arange(temp_min, temp_max, 1))
75
+
76
+ #Title表示
77
+ axes[1].set_title(title, fontsize=16)
78
+
79
+ #余白調整
80
+ plt.subplots_adjust(right=0.85)
81
+ plt.subplots_adjust(wspace=0.15)
82
+
83
+ # 視点
84
+ axes[1].view_init(30, -45)
85
+
86
+ #余白調整
87
+ plt.subplots_adjust(right=0.85)
88
+ plt.subplots_adjust(wspace=0.15)
24
- cv2.imwrite('/home/pi/dev/data/thermo/bicubic_3D.png', im_h)
89
+ plt.savefig('/home/pi/dev/data/thermo/bicubic_3D.png', format='png')
25
- except KeyboardInterrupt:
26
- pass
27
90
  ```
28
91
 
29
92
  ##困っていること
30
- プログラムを実行すると、次のエラーメッセージが出てしまいます。
93
+ プログラムを実行すると、次のような表示になってしまいます。
31
- 結合する2つの画像は保存されているので、結合する画像はあるはずですが、
32
- 結合の方法が間違えているのでしょうか?
33
- ```text
34
- libpng warning: Image width is zero in IHDR
35
- libpng warning: Image height is zero in IHDR
94
+ ![イメージ説明](6f0b4ccefd8f19c67beedb52a7e06174.png)
36
- libpng error: Invalid IHDR data
37
- ```

1

プログラムコード修正

2020/03/11 01:32

投稿

raspypy
raspypy

スコア247

title CHANGED
File without changes
body CHANGED
@@ -18,7 +18,7 @@
18
18
  if __name__ == '__main__':
19
19
  try:
20
20
  drawing1()
21
- drawing1()
21
+ drawing2()
22
22
  print ('Heat Mapping Generated...')
23
23
  im_h = cv2.hconcat([im1, im2])
24
24
  cv2.imwrite('/home/pi/dev/data/thermo/bicubic_3D.png', im_h)