【问题标题】:matplotlib Plot does not appearmatplotlib 绘图不出现
【发布时间】:2017-03-04 01:26:57
【问题描述】:

我正在使用带有 pycharm 和 anaconda 的 python v3.6。我试图运行下面的代码来绘制一个简单的正弦波;

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")
pass

代码运行顺利,没有错误,但没有出现任何情节。如何让情节出现?

【问题讨论】:

    标签: python python-3.x matplotlib anaconda


    【解决方案1】:

    最后你错过了plt.show()

    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
    

    或者,如果您想将其保存到文件中

    plt.savefig("my_file.png")
    

    【讨论】:

      猜你喜欢
      • 2012-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-22
      • 2018-02-22
      • 1970-01-01
      相关资源
      最近更新 更多