回答編集履歴
3
追記
test
CHANGED
@@ -3,3 +3,53 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
subplotを使うとしたら、データフレームを都道府県ごとに抽出して、`ax`引数にsubplotを渡せば良いのでは。
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
```python
|
10
|
+
|
11
|
+
import pandas as pd
|
12
|
+
|
13
|
+
import seaborn as sns
|
14
|
+
|
15
|
+
import matplotlib.pyplot as plt
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
# データフレームの準備
|
20
|
+
|
21
|
+
pref = ["東京", "東京", "東京", "埼玉", "埼玉", "埼玉", "東京", "東京", "埼玉", "埼玉"]
|
22
|
+
|
23
|
+
house = ["木造", "鉄骨", "木造", "鉄骨", "木造", "鉄骨", "鉄骨", "鉄骨", "木造", "木造"]
|
24
|
+
|
25
|
+
value = [100, 120, 100, 80, 80, 90, 90, 130, 100, 60]
|
26
|
+
|
27
|
+
df = pd.DataFrame({'都道府県':pref, '建物': house, '価格':value})
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
fig, axes = plt.subplots(7, 7, figsize=(50, 50), sharey=True)
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
pref_list = ["東京", "埼玉"]
|
36
|
+
|
37
|
+
for i, pref in enumerate(pref_list):
|
38
|
+
|
39
|
+
i, j = i // 7, i % 7
|
40
|
+
|
41
|
+
data = df.query(f"都道府県=='{pref}'")
|
42
|
+
|
43
|
+
sns.boxplot(x="都道府県", y="価格", hue="建物", data=data, ax=axes[i, j])
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
plt.show()
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
```
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
![イメージ説明](2ce23b6b40fb37c3662d34b39d48ec22.png)
|
2
ミスってたので一回消す
test
CHANGED
@@ -3,47 +3,3 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
subplotを使うとしたら、データフレームを都道府県ごとに抽出して、`ax`引数にsubplotを渡せば良いのでは。
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
```python
|
10
|
-
|
11
|
-
import pandas as pd
|
12
|
-
|
13
|
-
import seaborn as sns
|
14
|
-
|
15
|
-
import matplotlib.pyplot as plt
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
# データフレームの準備
|
20
|
-
|
21
|
-
pref = ["東京", "東京", "東京", "埼玉", "埼玉", "埼玉", "東京", "東京", "埼玉", "埼玉"]
|
22
|
-
|
23
|
-
house = ["木造", "鉄骨", "木造", "鉄骨", "木造", "鉄骨", "鉄骨", "鉄骨", "木造", "木造"]
|
24
|
-
|
25
|
-
value = [100, 120, 100, 80, 80, 90, 90, 130, 100, 60]
|
26
|
-
|
27
|
-
df = pd.DataFrame({'都道府県':pref, '建物': house, '価格':value})
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
fig, axes = plt.subplots(7, 7, figsize=(50, 50), sharey=True)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
pref_list = ["東京", "埼玉"]
|
36
|
-
|
37
|
-
for i, pref in enumerate(pref_list):
|
38
|
-
|
39
|
-
i, j = i // 7, i % 7
|
40
|
-
|
41
|
-
sns.boxplot(x="都道府県", y="価格", hue="建物", data=df, ax=axes[i, j])
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
plt.show()
|
46
|
-
|
47
|
-
```
|
48
|
-
|
49
|
-
![イメージ説明](0fc6924631e671f1aab8a79e92171724.png)
|
1
修正
test
CHANGED
@@ -2,8 +2,48 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
|
5
|
+
subplotを使うとしたら、データフレームを都道府県ごとに抽出して、`ax`引数にsubplotを渡せば良いのでは。
|
6
6
|
|
7
7
|
|
8
8
|
|
9
9
|
```python
|
10
|
+
|
11
|
+
import pandas as pd
|
12
|
+
|
13
|
+
import seaborn as sns
|
14
|
+
|
15
|
+
import matplotlib.pyplot as plt
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
# データフレームの準備
|
20
|
+
|
21
|
+
pref = ["東京", "東京", "東京", "埼玉", "埼玉", "埼玉", "東京", "東京", "埼玉", "埼玉"]
|
22
|
+
|
23
|
+
house = ["木造", "鉄骨", "木造", "鉄骨", "木造", "鉄骨", "鉄骨", "鉄骨", "木造", "木造"]
|
24
|
+
|
25
|
+
value = [100, 120, 100, 80, 80, 90, 90, 130, 100, 60]
|
26
|
+
|
27
|
+
df = pd.DataFrame({'都道府県':pref, '建物': house, '価格':value})
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
fig, axes = plt.subplots(7, 7, figsize=(50, 50), sharey=True)
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
pref_list = ["東京", "埼玉"]
|
36
|
+
|
37
|
+
for i, pref in enumerate(pref_list):
|
38
|
+
|
39
|
+
i, j = i // 7, i % 7
|
40
|
+
|
41
|
+
sns.boxplot(x="都道府県", y="価格", hue="建物", data=df, ax=axes[i, j])
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
plt.show()
|
46
|
+
|
47
|
+
```
|
48
|
+
|
49
|
+
![イメージ説明](0fc6924631e671f1aab8a79e92171724.png)
|