[PYTHON] Why do you often come across code that plt.show () is missing? When do you need plt.show ()?

Overview

As the title says. In an article related to deep learning using Python, I sometimes feel lonely when I run the sample code at hand and the image is not displayed. From experience, I remember or forgot that it would appear if I added plt.show (). .. .. ** Is it a difference in module version? ?? ?? Some people think that **.

I did some research, so I'll share the information.

I think there are many good articles already, but I've narrowed it down to plt.show ().

Result of investigation

Isn't this explanation good? (https://stackoverflow.com/questions/54422714/when-is-plt-show-required-to-show-a-plot-and-when-is-it-not)

The following answer was given in the following article. (Source: https://stackoverflow.com/questions/54422714/when-is-plt-show-required-to-show-a-plot-and-when-is-it-not)

To require or not required depending on where your script is.

There are 2 contexts.(

  • Matplotlib is used in a terminal or scripts, plt.show() is a must.

  • Matplotlib is used in a IPython shell or a notebook (ex: Kaggle), plt.show() is unnecessary.

Did you bother to quote this article because the cause is "only" related to ** jupyter notebook **? I thought, but ** I realized that it could be in another environment. ** **

The reason why the image is displayed even without plt.show () in Jupyter notebook.

The following article

https://docs.pyq.jp/python/pydata/jupyter/matplotlib.html

Excerpt and quote

(Citation) ** Jupyter Notebook outputs the object evaluated at the end of the cell. ** **

It seems.

** It seems that the evaluated object is output at the end of the cell **. So that's it. Then you don't have to bother to show.

Summary

Nothing in particular. If you have any comments, please let us know. : candy: (I used single quotes for the first time in the article.)

Recommended Posts

Why do you often come across code that plt.show () is missing? When do you need plt.show ()?
What to do when a Missing artifact occurs in a jar that is not defined in pom.xml