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

回答編集履歴

1

コメントに応じてサンプル修正

2018/07/13 12:11

投稿

magichan
magichan

スコア15898

answer CHANGED
@@ -18,4 +18,34 @@
18
18
  plt.yticks(range(len(pref)), pref)
19
19
  plt.scatter(x,y)
20
20
  plt.show()
21
+ ```
22
+
23
+ ---
24
+
25
+ **【追記】**
26
+
27
+ 以下を修正してみました
28
+ - 都道府県リストはborn_liveから生成するではなくて固定のものを使用
29
+ - X軸 Y軸共に範囲を指定
30
+ - X軸のtickを90度回転
31
+
32
+
33
+ ```Python
34
+ import matplotlib.pyplot as plt
35
+
36
+ born_live = [('gunma', 'tokyo'), ('tochigi', 'hokkaido') , ('tokyo', 'tokyo'), ('nagano', 'nagano'), ('miyazaki', 'fukuoka')]
37
+
38
+ # 都道府県のリストは既知
39
+ pref = ['hokkaido', 'gunma', 'tochigi', 'tokyo' , 'nagano', 'fukuoka', 'miyazaki', 'okinawa']
40
+
41
+ x = [pref.index(x) for x,y in born_live]
42
+ y = [pref.index(y) for x,y in born_live]
43
+
44
+ plt.scatter(x,y)
45
+ plt.xticks(range(len(pref)), pref, rotation='vertical')
46
+ plt.yticks(range(len(pref)), pref)
47
+ plt.xlim(0, len(pref)-1) # X軸の範囲を指定
48
+ plt.ylim(0, len(pref)-1) # Y軸の範囲を指定
49
+ plt.tight_layout()
50
+ plt.show()
21
51
  ```