'How does one set keyword "block" in plt.show() equal to True by default?

For some reason, I need to set the keyword "block" equal to True explicitly, so that plots are shown when I run a script from the bash shell. (I don't need that when I run it from the ipython shell). How can I set that argument to True by default as nearly everyone seems to have it?

Sample:

import matplotlib.pyplot as plt

plt.plot([1,2,3], [1,2,3])

plt.show(block=True) 

I would like plots to show up even if that argument isn't set to True explicitly, that is:

import matplotlib.pyplot as plt

plt.plot([1,2,3], [1,2,3])

plt.show() 

My matplotlibrc contains:

backend : MacOSX

interactive : True

toolbar : toolbar2
timezone : UTC



Solution 1:[1]

The 'interactive' mode of mpl determines the behavior of plt.show. If in 'interactive' mode, it assumes that there is something else managing the GUI event loop. When running a script with

python -i script.py

will drop you into an interactive shell. When siting in the REPL, there is integration between the python REPL loop and the GUI event loop which allows the GUI loop to run in the background, which makes the figure 'interactive'. If 'interactive' mode was not on in this case, you would not get the prompt until you have closed the figure.

'interactive' mode can be enabled either by calling plt.ion() or by setting the 'interactive' key in matplotlibrc.

I strongly suggest that you leave the rcparam value to be False.

Solution 2:[2]

kwargs = dict(type='candle',mav=(10),volume=True,figratio=(11,8),figscale=0.85, block=True)

mpf.plot(dfless, **kwargs, style='classic')

putting it inside the kwargs worked well for me

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tacaswell
Solution 2 makmak