代码
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
print type(ax)
给出输出
<class 'matplotlib.axes.AxesSubplot'>
然后是代码
import matplotlib.axes
matplotlib.axes.AxesSubplot
引发异常
AttributeError: 'module' object has no attribute 'AxesSubplot'
总而言之,有一个类matplotlib.axes.AxesSubplot
,但是模块matplotlib.axes
没有属性AxesSubplot
。这到底是怎么回事?
我使用的是Matplotlib 1.1.0和Python 2.7.3。
发布于 2019-11-17 02:10:12
了解DSM所说内容的另一种方式:
In [1]: from matplotlib import pyplot as plt
In [2]: type(plt.gca()).__mro__
Out[2]:
(matplotlib.axes._subplots.AxesSubplot,
matplotlib.axes._subplots.SubplotBase,
matplotlib.axes._axes.Axes,
matplotlib.axes._base._AxesBase,
matplotlib.artist.Artist,
object)
使用dunder method resolution order,您可以找到某个类的所有继承。
https://stackoverflow.com/questions/11690597
复制相似问题