- 実行したいこと
datetime型と数値のlistを使って、散布図を作成しようとしています。
- 実行環境
Python 3.6.5 :: Anaconda custom (64-bit)
- 起きていること
下記のソースを実行するとエラーになってしまいます。
解決策を教えていただけますでしょうか。
python3
1import matplotlib 2 3print(trans_hist) 4[[datetime.datetime(2018, 5, 16, 0, 3), 2204534], 5 [datetime.datetime(2018, 5, 16, 0, 2), 2204534], 6 [datetime.datetime(2018, 5, 15, 22, 3), 2249228], 7 [datetime.datetime(2018, 5, 15, 20, 45), 2249228], 8 [datetime.datetime(2018, 5, 15, 20, 3), 2347108], 9 [datetime.datetime(2018, 5, 15, 20, 2), 2347108], 10 [datetime.datetime(2018, 5, 15, 18, 3), 2338388], 11 [datetime.datetime(2018, 5, 15, 18, 2), 2338388], 12 [datetime.datetime(2018, 5, 15, 16, 3), 2372737], 13 [datetime.datetime(2018, 5, 15, 16, 2), 2372737], 14 [datetime.datetime(2018, 5, 15, 14, 4), 2346901], 15 [datetime.datetime(2018, 5, 15, 13, 55), 2346901], 16 [datetime.datetime(2018, 5, 15, 12, 3), 2435001], 17 [datetime.datetime(2018, 5, 15, 12, 2), 2435001], 18 [datetime.datetime(2018, 5, 15, 10, 3), 2425497], 19 [datetime.datetime(2018, 5, 15, 10, 2), 2425497], 20 [datetime.datetime(2018, 5, 15, 8, 3), 2441297], 21 [datetime.datetime(2018, 5, 15, 8, 2), 2441297], 22 [datetime.datetime(2018, 5, 15, 6, 3), 2464897], 23 [datetime.datetime(2018, 5, 15, 6, 2), 2464897], 24 [datetime.datetime(2018, 5, 15, 5, 0), 2478579], 25 [datetime.datetime(2018, 5, 15, 4, 3), 2478687], 26 [datetime.datetime(2018, 5, 15, 3, 4), 2478687], 27 [datetime.datetime(2018, 5, 15, 2, 4), 2553465], 28 [datetime.datetime(2018, 5, 15, 2, 2), 2553465], 29 [datetime.datetime(2018, 5, 15, 0, 5), 2485630], 30 [datetime.datetime(2018, 5, 15, 0, 2), 2485630], 31 [datetime.datetime(2018, 5, 14, 22, 4), 2517109], 32 [datetime.datetime(2018, 5, 14, 22, 2), 2517109], 33 [datetime.datetime(2018, 5, 14, 20, 3), 2546648], 34 [datetime.datetime(2018, 5, 14, 20, 2), 2546648], 35 [datetime.datetime(2018, 5, 14, 18, 3), 2509764], 36 [datetime.datetime(2018, 5, 14, 18, 2), 2509764], 37 [datetime.datetime(2018, 5, 14, 16, 4), 2540629], 38 [datetime.datetime(2018, 5, 14, 16, 2), 2540629], 39 [datetime.datetime(2018, 5, 14, 14, 3), 2587707], 40 [datetime.datetime(2018, 5, 14, 14, 2), 2587707], 41 [datetime.datetime(2018, 5, 14, 12, 3), 2622980], 42 [datetime.datetime(2018, 5, 14, 12, 2), 2622980], 43 [datetime.datetime(2018, 5, 14, 10, 3), 2644520], 44 [datetime.datetime(2018, 5, 14, 10, 2), 2644520], 45 [datetime.datetime(2018, 5, 14, 8, 3), 2602869], 46 [datetime.datetime(2018, 5, 14, 8, 2), 2602869], 47 [datetime.datetime(2018, 5, 14, 6, 3), 2625191], 48 [datetime.datetime(2018, 5, 12, 4, 2), 2625191], 49 [datetime.datetime(2018, 5, 12, 2, 3), 2637987], 50 [datetime.datetime(2018, 5, 12, 2, 2), 2637987], 51 [datetime.datetime(2018, 5, 12, 0, 3), 2581568], 52 [datetime.datetime(2018, 5, 12, 0, 2), 2581568], 53 [datetime.datetime(2018, 5, 11, 22, 3), 2632897]] 54 55matplotlib.pyplot.scatter(trans_hist[0],trans_hist[1]) 56matplotlib.pyplot.show() 57matplotlib.pyplot.close() 58
- 実行時のエラーメッセージ
python3
1AttributeErrorTraceback (most recent call last) 2<ipython-input-81-0601ce12c380> in <module>() 3 1 #matplotlib.pyplot.scatter(trans_hist[0],trans_hist[1]) 4----> 2 matplotlib.pyplot.scatter(trans_hist[0],trans_hist[1]) 5 3 matplotlib.pyplot.show() 6 4 matplotlib.pyplot.close() 7 8~/anaconda3/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) 9 3468 vmin=vmin, vmax=vmax, alpha=alpha, 10 3469 linewidths=linewidths, verts=verts, 11-> 3470 edgecolors=edgecolors, data=data, **kwargs) 12 3471 finally: 13 3472 ax._hold = washold 14 15~/anaconda3/lib/python3.6/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs) 16 1853 "the Matplotlib list!)" % (label_namer, func.__name__), 17 1854 RuntimeWarning, stacklevel=2) 18-> 1855 return func(ax, *args, **kwargs) 19 1856 20 1857 inner.__doc__ = _add_data_doc(inner.__doc__, 21 22~/anaconda3/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) 23 4232 24 4233 self._process_unit_info(xdata=x, ydata=y, kwargs=kwargs) 25-> 4234 x = self.convert_xunits(x) 26 4235 y = self.convert_yunits(y) 27 4236 28 29~/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py in convert_xunits(self, x) 30 189 if ax is None or ax.xaxis is None: 31 190 return x 32--> 191 return ax.xaxis.convert_units(x) 33 192 34 193 def convert_yunits(self, y): 35 36~/anaconda3/lib/python3.6/site-packages/matplotlib/axis.py in convert_units(self, x) 37 1524 return x 38 1525 39-> 1526 ret = self.converter.convert(x, self.units, self) 40 1527 return ret 41 1528 42 43~/anaconda3/lib/python3.6/site-packages/matplotlib/dates.py in convert(value, unit, axis) 44 1814 The *unit* and *axis* arguments are not used. 45 1815 """ 46-> 1816 return date2num(value) 47 1817 48 1818 @staticmethod 49 50~/anaconda3/lib/python3.6/site-packages/matplotlib/dates.py in date2num(d) 51 450 if not d.size: 52 451 return d 53--> 452 return _to_ordinalf_np_vectorized(d) 54 453 55 454 56 57~/anaconda3/lib/python3.6/site-packages/numpy/lib/function_base.py in __call__(self, *args, **kwargs) 58 2753 vargs.extend([kwargs[_n] for _n in names]) 59 2754 60-> 2755 return self._vectorize_call(func=func, args=vargs) 61 2756 62 2757 def _get_ufunc_and_otypes(self, func, args): 63 64~/anaconda3/lib/python3.6/site-packages/numpy/lib/function_base.py in _vectorize_call(self, func, args) 65 2829 for a in args] 66 2830 67-> 2831 outputs = ufunc(*inputs) 68 2832 69 2833 if ufunc.nout == 1: 70 71~/anaconda3/lib/python3.6/site-packages/matplotlib/dates.py in _to_ordinalf(dt) 72 253 tzi = UTC 73 254 74--> 255 base = float(dt.toordinal()) 75 256 76 257 # If it's sufficiently datetime-like, it will have a `date()` method 77 78AttributeError: 'int' object has no attribute 'toordinal' 79
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/16 05:18
2018/05/16 05:45