hsf-training / hsf-training-matplotlib

Create commonly used plots in HEP with matplotlib and mplhep
https://hsf-training.github.io/hsf-training-matplotlib/
Other
4 stars 9 forks source link

matplotlib inline and plt.show() #126

Open klieret opened 2 years ago

klieret commented 2 years ago

Was also a question at pyhep: Is plt.show() really necessary?

I think we should explain what it does and also %matplotlib inline.

Might also talk about how return values are shown (sometimes leading to plots being shown double, which is why people then add ;...)

klieret commented 2 years ago

The %matplotlib inline is only needed for Classic Jupyter. JupyterLab recognizes Matplotlib out of the box.

From @jpivarski

jpivarski commented 2 years ago

The rationale for plt.show() that Alex Briceño gave, that it prevents the Matplotlib object repr from being shown, is not a strong reason. The same would be accomplished by replacing "plt.show()" with "None". What's happening is that Jupyter is showing the repr of the last Python object returned by the last line in the cell. (plt.show() returns None.)

A better argument could be made that plt.show() is necessary when you're not in Jupyter, but then the workflow is entirely different: if it's in a single threaded Python commandline, you don't get access to do anything in Python until you close the window that plt.show() pops up. So that's not a very friendly way of working, anyway. But anyway, including the plt.show() is indicating where it would be needed if you weren't using Jupyter, in case somebody needs to know that.

amorenobr commented 2 years ago

Thanks Jim for the clarification!

stale[bot] commented 1 year ago

This issue or pull request has been automatically marked as stale because it has not had recent activity. Please manually close it, if it is no longer relevant, or ask for help or support to help getting it unstuck. Let me bring this to the attention of @klieret @wdconinc @michmx for now.