Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8300311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:31:10+00:00 2026-06-08T16:31:10+00:00

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

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T16:31:14+00:00Added an answer on June 8, 2026 at 4:31 pm

    Heh. That’s because there is no AxesSubplot class.. until one is needed, when one is built from SubplotBase. This is done by some magic in axes.py:

    def subplot_class_factory(axes_class=None):
        # This makes a new class that inherits from SubplotBase and the
        # given axes_class (which is assumed to be a subclass of Axes).
        # This is perhaps a little bit roundabout to make a new class on
        # the fly like this, but it means that a new Subplot class does
        # not have to be created for every type of Axes.
        if axes_class is None:
            axes_class = Axes
    
        new_class = _subplot_classes.get(axes_class)
        if new_class is None:
            new_class = new.classobj("%sSubplot" % (axes_class.__name__),
                                     (SubplotBase, axes_class),
                                     {'_axes_class': axes_class})
            _subplot_classes[axes_class] = new_class
    
        return new_class
    

    So it’s made on the fly, but it’s a subclass of SubplotBase:

    >>> import matplotlib.pyplot as 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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

PROBLEM: Here's the code: import matplotlib.pyplot as plt plt.bar([1,2],[5,4]) plt.title('this is a very long
I have the following code: import matplotlib.pyplot as plt cdict = { 'red' :
import sys import matplotlib import matplotlib.pyplot as plt print matplotlib.__version__, matplotlib.get_backend() def hit(event): sys.stderr.write('hit\n')
Consider the following code: from numpy import log2 import matplotlib.pyplot as plt xdata =
Here is my code: import matplotlib.pyplot as plt plt.loglog(length,time,'--') where length and time are
Sometimes I come across code such as this: import matplotlib.pyplot as plt x =
i have the following code: import scipy as sc import matplotlib.pyplot as plt ....
I have some code: #!/usr/bin/env python import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt x
The following code fails to run on Python 2.5.4: from matplotlib import pylab as
code: import urllib,urllib2 url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php' print urllib2.urlopen(url).read() print urllib2.urlopen(url,urllib.urlencode({'nothing':12345})).read() the question I encounter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.