Matplotlib image not coming up in Visual Studio Code on Mac

前端 未结 2 699
天涯浪人
天涯浪人 2021-01-13 04:28

I\'m running some basic code in the Visual Studio Code editor on MacOSX:

    import matplotlib.pyplot as plt
    import numpy as np
    x = np.linspace(0, 20         


        
2条回答
  •  一整个雨季
    2021-01-13 05:30

    When running matplotlib codes from the terminal, I experience the same kind of hanging of the application after saving the image to a file. In this case, one 'workaround' that has always worked for me is to turn off blocking. Basically alter your code in this way:

    import matplotlib.pyplot as plt
    import numpy as np
    x = np.linspace(0, 20, 100)
    plt.plot(x, np.sin(x))
    plt.show(block=False)
    input('press  to continue')
    

    It's not perfect, but the image is saved correctly and the application stops after you hit ENTER in the terminal. Hope this helps.

提交回复
热议问题