drake
drake

Reputation: 1122

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

Upvotes: 4

Views: 12352

Answers (2)

makmak
makmak

Reputation: 151

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

Upvotes: 0

tacaswell
tacaswell

Reputation: 87486

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.

Upvotes: 4

Related Questions