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

質問編集履歴

1

試したことの追記

2018/07/13 12:06

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -31,6 +31,102 @@
31
31
  plt.show()
32
32
  ```
33
33
 
34
+ ### 試したこと
35
+ リストを使いたいのですが、まずはX軸とY軸を描画するために、
36
+ 以下のコードを実行しました。
37
+ ```python
38
+ import matplotlib.pyplot as plt
39
+
40
+ born_live = [('gunma', 'tokyo'), ('tochigi', 'hokkaido') , ('tokyo', 'tokyo'), ('nagano', 'nagano'), ('miyazaki', 'fukuoka')]
41
+
42
+ # 都道府県のリスト作成
43
+ pref = [d for d in set(sum(map(list, born_live), []))]
44
+
45
+ x = ['hokkaido', 'gunma', 'tochigi', 'tokyo', 'nagano', 'miyazaki', 'fukuoka']
46
+ y = ['hokkaido', 'gunma', 'tochigi', 'tokyo', 'nagano', 'miyazaki', 'fukuoka']
47
+
48
+ plt.xticks(range(len(pref)), pref)
49
+ plt.yticks(range(len(pref)), pref)
50
+ plt.scatter(x,y)
51
+ plt.show()
52
+ ```
53
+ ![イメージ説明](442f784c0f4251cbb137de08c19f817b.png)
54
+
55
+ この時点で、入力したX軸・Y軸の要素の順番が異なるのですが、
56
+ 更に、以下のようにリストと同じようにプロットを打とうとしたところ、
57
+ エラーが出力されてしまっている状態です。
58
+ ```python
59
+ import matplotlib.pyplot as plt
60
+
61
+ born_live = [('gunma', 'tokyo'), ('tochigi', 'hokkaido') , ('tokyo', 'tokyo'), ('nagano', 'nagano'), ('miyazaki', 'fukuoka')]
62
+
63
+ # 都道府県のリスト作成
64
+ pref = [d for d in set(sum(map(list, born_live), []))]
65
+
66
+ x = ['hokkaido', 'gunma', 'tochigi', 'tokyo', 'nagano', 'miyazaki', 'fukuoka']
67
+ y = [None, 'tokyo', 'hokkaido', 'tokyo', 'nagano', 'fukuoka', None]
68
+
69
+ plt.xticks(range(len(pref)), pref)
70
+ plt.yticks(range(len(pref)), pref)
71
+ plt.scatter(x,y)
72
+ plt.show()
73
+ ```
74
+
75
+ エラー文
76
+ ```
77
+ --------------------------------------------------------------------------
78
+ ValueError Traceback (most recent call last)
79
+ <ipython-input-4-457a837ce2d3> in <module>()
80
+ 11 plt.xticks(range(len(pref)), pref)
81
+ 12 plt.yticks(range(len(pref)), pref)
82
+ ---> 13 plt.scatter(x,y)
83
+ 14 plt.show()
84
+
85
+ ~/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/matplotlib/pyplot.py in scatter(x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, hold, data, **kwargs)
86
+ 3355 vmin=vmin, vmax=vmax, alpha=alpha,
87
+ 3356 linewidths=linewidths, verts=verts,
88
+ -> 3357 edgecolors=edgecolors, data=data, **kwargs)
89
+ 3358 finally:
90
+ 3359 ax._hold = washold
91
+
92
+ ~/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
93
+ 1708 warnings.warn(msg % (label_namer, func.__name__),
94
+ 1709 RuntimeWarning, stacklevel=2)
95
+ -> 1710 return func(ax, *args, **kwargs)
96
+ 1711 pre_doc = inner.__doc__
97
+ 1712 if pre_doc is None:
98
+
99
+ ~/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/matplotlib/axes/_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)
100
+ 4094 offsets=offsets,
101
+ 4095 transOffset=kwargs.pop('transform', self.transData),
102
+ -> 4096 alpha=alpha
103
+ 4097 )
104
+ 4098 collection.set_transform(mtransforms.IdentityTransform())
105
+
106
+ ~/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/matplotlib/collections.py in __init__(self, paths, sizes, **kwargs)
107
+ 859 """
108
+ 860
109
+ --> 861 Collection.__init__(self, **kwargs)
110
+ 862 self.set_paths(paths)
111
+ 863 self.set_sizes(sizes)
112
+
113
+ ~/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/matplotlib/collections.py in __init__(self, edgecolors, facecolors, linewidths, linestyles, antialiaseds, offsets, transOffset, norm, cmap, pickradius, hatch, urls, offset_position, zorder, **kwargs)
114
+ 147 self._uniform_offsets = None
115
+ 148 if offsets is not None:
116
+ --> 149 offsets = np.asanyarray(offsets, float)
117
+ 150 # Broadcast (2,) -> (1, 2) but nothing else.
118
+ 151 if offsets.shape == (2,):
119
+
120
+ ~/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/numpy/core/numeric.py in asanyarray(a, dtype, order)
121
+ 581
122
+ 582 """
123
+ --> 583 return array(a, dtype, copy=False, order=order, subok=True)
124
+ 584
125
+ 585
126
+
127
+ ValueError: could not convert string to float: 'fukuoka'
128
+ ```
129
+
34
130
  ### 補足情報(FW/ツールのバージョンなど)
35
131
  Python 3.6
36
132
  Jupyter notebook 5.0.0