我试图用matplotlib做最简单的可能的1行2列多ax绘图,实际上是taken from the examples in the documentation:
from matplotlib import pyplot as plt
fig, (ax1, ax2) = plt.subplot(nrows=1, ncols=2, sharey=True)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-9-4bc4f1ccd8e8> in <module>
1 from matplotlib import pyplot as plt
----> 2 fig, (ax1, ax2) = plt.subplot(nrows=1, ncols=2, sharey=True)
~/.virtualenvs/tcpsp/lib/python3.7/site-packages/matplotlib/pyplot.py in subplot(*args, **kwargs)
1082
1083 fig = gcf()
-> 1084 a = fig.add_subplot(*args, **kwargs)
1085 bbox = a.bbox
1086 byebye = []
~/.virtualenvs/tcpsp/lib/python3.7/site-packages/matplotlib/figure.py in add_subplot(self, *args, **kwargs)
1365 self._axstack.remove(ax)
1366
-> 1367 a = subplot_class_factory(projection_class)(self, *args, **kwargs)
1368 self._axstack.add(key, a)
1369 self.sca(a)
~/.virtualenvs/tcpsp/lib/python3.7/site-packages/matplotlib/axes/_subplots.py in __init__(self, fig, *args, **kwargs)
68
69 # _axes_class is set in the subplot_class_factory
---> 70 self._axes_class.__init__(self, fig, self.figbox, **kwargs)
71 # add a layout box to this, for both the full axis, and the poss
72 # of the axis. We need both because the axes may become smaller
~/.virtualenvs/tcpsp/lib/python3.7/site-packages/matplotlib/axes/_base.py in __init__(self, fig, rect, facecolor, frameon, sharex, sharey, label, xscale, yscale, **kwargs)
471 self._shared_x_axes.join(self, sharex)
472 if sharey is not None:
--> 473 self._shared_y_axes.join(self, sharey)
474 self.set_label(label)
475 self.set_figure(fig)
~/.virtualenvs/tcpsp/lib/python3.7/site-packages/matplotlib/cbook/__init__.py in join(self, a, *args)
923
924 for arg in args:
--> 925 set_b = mapping.get(weakref.ref(arg), [weakref.ref(arg)])
926 if set_b is not set_a:
927 if len(set_b) > len(set_a):
TypeError: cannot create weak reference to 'bool' object
<Figure size 432x288 with 0 Axes>
我真的不知道为什么它试图创建对bool
的弱引用。你知道吗
我使用的是matplotlib和Python的最新版本:
import sys
print(sys.version)
3.7.0 (default, Sep 12 2018, 18:30:08)
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]]
import matplotlib
matplotlib.__version__
'3.0.2'
我认为文档中的示例应该有效,对吗?这是Matplotlib错误还是我做错了什么?你知道吗
首先,使用
plt.subplots()
在您想单独自定义每个绘图之前,不解包ax子绘图变量可能更容易。你知道吗
通常我会这样做:
因此,如果我需要在全球范围内应用任何东西,我可以做:
然后分别:
这也可以很好地扩展,因此,如果我使用的是2x2的绘图矩阵(就像我现在这样),区别很简单:
相关问题 更多 >
编程相关推荐