Matplotlib - Force plot display and then return to main code

后端 未结 3 1512
心在旅途
心在旅途 2020-12-30 01:32

This is a MWE of what I\'m after, adapted from this question:

from matplotlib.pyplot import plot, draw, show

def make_plot():
    plot([1,2,3])
    draw()
          


        
3条回答
  •  没有蜡笔的小新
    2020-12-30 02:08

    You may use plt.show(block=False), which gets rid of the blocking directly.

    For your example, this could read

    from matplotlib.pyplot import plot, show
    
    def make_plot():
        plot([1,2,3])
        show(block=False)
        print('continue computation')
    
    print('Do something before plotting.')
    # Now display plot in a window
    make_plot()
    
    answer = input('Back to main and window visible? ')
    if answer == 'y':
        print('Excellent')
    else:
        print('Nope')
    

提交回复
热议问题