close

[Solved] matplotlib: AttributeError: ‘AxesSubplot’ object has no attribute ‘add_axes’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error matplotlib: AttributeError: ‘AxesSubplot’ object has no attribute ‘add_axes’ in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How matplotlib: AttributeError: ‘AxesSubplot’ object has no attribute ‘add_axes’ Error Occurs?

Today I get the following error matplotlib: AttributeError: ‘AxesSubplot’ object has no attribute ‘add_axes’ in python.

How To Solve matplotlib: AttributeError: ‘AxesSubplot’ object has no attribute ‘add_axes’ Error ?

  1. How To Solve matplotlib: AttributeError: 'AxesSubplot' object has no attribute 'add_axes' Error ?

    To Solve matplotlib: AttributeError: 'AxesSubplot' object has no attribute 'add_axes' Error
    You now need to use set_prop_cycle i.e. ax.set_prop_cycle(color=['red', 'green', 'blue'])

  2. matplotlib: AttributeError: 'AxesSubplot' object has no attribute 'add_axes'

    To Solve matplotlib: AttributeError: 'AxesSubplot' object has no attribute 'add_axes' Error
    You now need to use set_prop_cycle i.e. ax.set_prop_cycle(color=['red', 'green', 'blue'])

Solution 1

There’s not much details to go on in your question but I’ll wager a guess. The error is pretty self-explanatory. You can’t add_axes to pyplot_2 because pyplot_2 is a matplotlib.axes.AxesSubplot object and they don’t have an add_axes method defined.

Only matplotlib.figure.Figure objects have add_axes method defined on them.

From what I got from a short browse through the WCSAxes official documentation their recommended approach would be:

wcs = astropy.wcs.WCS(....)
fig = matplotlib.pyplot.figure()
pyplot_2 = fig.add_subplot(gridspec_layout[2], projection=wcs)

Solution 2

You now need to use set_prop_cycle i.e. ax.set_prop_cycle(color=['red', 'green', 'blue'])

Axes.set_color_cycle(clist) was depreciated since, version 1.5.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read