Different behaviour of matplotlib in interpretor and in script
Question: Running following code inside python interpretor displays a figure with random
values

    
    
    >>>fig = plt.figure();ax1 = fig.add_subplot(111);plt.ion();ax1 = ax1.imshow(np.random.rand(256,256))
    

while running the following script as a file does not display any
output/figure.

    
    
    import numpy as np
    import matplotlib.pyplot as plt
    import time
    
    fig = plt.figure()
    ax1 = fig.add_subplot(111)
    plt.ion()
    ax1 =ax1.imshow(np.random.rand(256,256))
    

what is the reason for difference in behaviour?


Answer: I suspect what is going on is that

    
    
    matplotlib.rcParams['interactive'] == True
    

and this is set in your `.matplotlibrc` file.

which means that `plt.show` is non-blocking (so that you get a figure that you
can interact with _and_ an command prompt you can type more code at). However,
in the case of a script the (implicit) `plt.show` does not block so the script
exits, taking the figure with it.

I suggest the setting the `interactive` rcparam to `False` and then either
explitily setting it to true in the repl or (the preferred method) use
`IPython` and the `%matplotlib` magic.

