There is a class matplotlib.axes.AxesSubplot, but the module matplotlib.axes has no attribute AxesSubplot

Viewed 20067

The code

import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
print type(ax)

gives the output

<class 'matplotlib.axes.AxesSubplot'>

Then the code

import matplotlib.axes
matplotlib.axes.AxesSubplot

raises the exception

AttributeError: 'module' object has no attribute 'AxesSubplot'

To summarize, there is a class matplotlib.axes.AxesSubplot, but the module matplotlib.axes has no attribute AxesSubplot. What on earth is going on?

I'm using Matplotlib 1.1.0 and Python 2.7.3.

2 Answers

Another way to see what DSM said:

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)

with the dunder method resolution order you can find all the inheritances of some class.

Related