45

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?

3 Answers 3

69

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
Sign up to request clarification or add additional context in comments.

Comments

38

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

fig2.figure 

3 Comments

Very useful with the objects a Seaborn lineplot presently returns. You can have the plot display again in another Jupyter cell without running all the code again.
Also, this was the only line of code that worked on Databricks when I was trying to display dicom files with matplotlib. Thanks!
I've really struggled to discern when/how to show, customize, and pass-around pyplot objects and this simple insight helped me tremendously. Go figure...
-1

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

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

plt.show()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.