matplotlib Plot does not appear

后端 未结 1 1015
温柔的废话
温柔的废话 2021-01-28 06:07

I am using python v3.6 with pycharm and anaconda. I tried to run the code below to plot a simple sine wave;

import numpy as np
import matplotlib.pyplot as pl         


        
1条回答
  •  执笔经年
    2021-01-28 06:53

    You're missing plt.show() at the end.

    import numpy as np
    import matplotlib.pyplot as plt
    
    # Generate a sequence of numbers from -10 to 10 with 100 steps in between
    x = np.linspace(-10, 10, 100)
    # Create a second array using sine
    y = np.sin(x)
    # The plot function makes a line chart of one array against another
    plt.plot(x, y, marker="x")
    plt.show()
    pass
    

    or, if you want to save it into a file

    plt.savefig("my_file.png")
    

    0 讨论(0)
提交回复
热议问题