How to show an AxesSubplot in Python?

Question:

I have an object fig2 that is a class mathplotlib.axes.axessubplot, but when I try to execute fig2.show(), python says axessubplot object has no attribute show. How can I show AxesSubplot?

Asked By: user3765587

||

Answers:

You should call matplotlib.pyplot.show(), which is a method that displays all the figures.

If you have imported as plt, then:

import matplotlib.pyplot as plt

# create fig1 (of type plt.figure)
# create fig2

plt.show()  # will display fig1 and fig2 in different windows
Answered By: heltonbiker

Alternatively, you could call the figure attribute of your fig2:

fig2.figure 
Answered By: Bython

import matplotlib.pyplot as plt – This statement will remove the error.

without thr first line, plt.show() would throw an attribute error.

plt.show()

Answered By: Gopal Sankar
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.