python - There is a class matplotlib.axes.AxesSubplot, but the module matplotlib.axes has no attribute AxesSubplot -
the code
import matplotlib.pyplot plt fig = plt.figure() ax = fig.add_subplot(111) print type(ax)
gives output
<class 'matplotlib.axes.axessubplot'>
then code
import matplotlib.axes matplotlib.axes.axessubplot
raises exception
attributeerror: 'module' object has no attribute 'axessubplot'
to summarize, there class matplotlib.axes.axessubplot
, module matplotlib.axes
has no attribute axessubplot
. on earth going on?
i'm using matplotlib 1.1.0 , python 2.7.3.
heh. that's because there is no axessubplot
class.. until 1 needed, when 1 built subplotbase
. done magic in axes.py
:
def subplot_class_factory(axes_class=none): # makes new class inherits subplotbase , # given axes_class (which assumed subclass of axes). # perhaps little bit roundabout create new class on # fly this, means new subplot class # not have created every type of axes. if axes_class none: axes_class = axes new_class = _subplot_classes.get(axes_class) if new_class none: new_class = new.classobj("%ssubplot" % (axes_class.__name__), (subplotbase, axes_class), {'_axes_class': axes_class}) _subplot_classes[axes_class] = new_class homecoming new_class
so it's made on fly, it's subclass of subplotbase
:
>>> import matplotlib.pyplot plt >>> fig = plt.figure() >>> ax = fig.add_subplot(111) >>> print type(ax) <class 'matplotlib.axes.axessubplot'> >>> b = type(ax) >>> import matplotlib.axes >>> issubclass(b, matplotlib.axes.subplotbase) true
python matplotlib
No comments:
Post a Comment