やろうとしたこと
np.meshgrid命令を使って、グラフをマス目状に区切った点データを
作ろうとしました。
該当のソースコード
import matplotlib.pyplot as plt
import numpy as np
plt.subplot(figsize=(15, 5))
# pcolormeshを使うと、表示範囲を分割して塗りつぶすことができる
# 3×3、8×8、100×100と細かくするほどなめらかになる
sizelist = [3,8,100]
for i in range(3):
size=sizelist[i]
X,Y = np.meshgrid(np.linspace(0, 10, size+1),
np.linspace(0, 10, size+1))
C = np.linspace(0,100,size*size).reshape(size, size)
plt.subplot(1, 3, i+1)
plt.pcolormesh(X,Y,C, cmap="rainbow")
plt.show()
発生している問題・エラーメッセージ
エラーメッセージ
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_2868/3552133022.py in <module>
2 import numpy as np
3
----> 4 plt.subplot(figsize=(15, 5))
5
6 # pcolormeshを使うと、表示範囲を分割して塗りつぶすことができる
~\anaconda3\lib\site-packages\matplotlib\pyplot.py in subplot(*args, **kwargs)
1285 else:
1286 # we have exhausted the known Axes and none match, make a new one!
-> 1287 ax = fig.add_subplot(*args, **kwargs)
1288
1289 fig.sca(ax)
~\anaconda3\lib\site-packages\matplotlib\figure.py in add_subplot(self, *args, **kwargs)
782 projection_class, pkw = self._process_projection_requirements(
783 *args, **kwargs)
--> 784 ax = subplot_class_factory(projection_class)(self, *args, **pkw)
785 key = (projection_class, pkw)
786 return self._add_axes_internal(ax, key)
~\anaconda3\lib\site-packages\matplotlib\axes_subplots.py in init(self, fig, *args, **kwargs)
34 """
35 # _axes_class is set in the subplot_class_factory
---> 36 self._axes_class.init(self, fig, [0, 0, 1, 1], **kwargs)
37 # This will also update the axes position.
38 self.set_subplotspec(SubplotSpec._from_subplot_args(fig, args))
~\anaconda3\lib\site-packages\matplotlib_api\deprecation.py in wrapper(*args, **kwargs)
469 "parameter will become keyword-only %(removal)s.",
470 name=name, obj_type=f"parameter of {func.name}()")
--> 471 return func(*args, **kwargs)
472
473 return wrapper
~\anaconda3\lib\site-packages\matplotlib\axes_base.py in init(self, fig, rect, facecolor, frameon, sharex, sharey, label, xscale, yscale, box_aspect, **kwargs)
646 self.set_yscale(yscale)
647
--> 648 self.update(kwargs)
649
650 for name, axis in self._get_axis_map().items():
~\anaconda3\lib\site-packages\matplotlib\artist.py in update(self, props)
1060 func = getattr(self, f"set_{k}", None)
1061 if not callable(func):
-> 1062 raise AttributeError(f"{type(self).name!r} object "
1063 f"has no property {k!r}")
1064 ret.append(func(v))
AttributeError: 'AxesSubplot' object has no property 'figsize'
<Figure size 432x288 with 0 Axes>Python バージョン
Python 3.6.1
ここにより詳細な情報を記載してください。
当初13行、14行、15行のSyntax Errorが表示されたため再度
打ち直しをして進めたとろころ、最終的に上述したエラーが表示されました。