【问题标题】:matplotlib versions 2.2.0 returns error in plt.showmatplotlib 版本 2.2.0 在 plt.show 中返回错误
【发布时间】:2019-02-25 20:49:14
【问题描述】:

我想绘图,但我遇到了一些错误

import numpy as np
import matplotlib as plt
x = np.arange(0, 3 * np.pi, 0.1)
y = np.sin(x)
plt.plot(x, y)
plt.show()

它有什么问题?

在 __ init__.py 中找不到引用“arange” 我在 Windows 10 上使用 pycharm

matplotlib.pymatplotlib.pyplot 之间有什么区别吗? 我找不到第二个

已解决:使用版本 2.1.2

【问题讨论】:

标签: python matplotlib


【解决方案1】:

您的 matplotlib 导入不正确。 使用import matplotlib.pyplot as plt(注意那里额外的.pyplot

它应该可以正常运行。

【讨论】:

    【解决方案2】:

    问题出在我的 matplotlib 版本上 我已经安装了 v.2.2.0。卸载它并安装 v.2.1.2 然后这段代码开始工作。

    【讨论】:

      【解决方案3】:

      首先检查您的numpymatplotlib 库的版本以及您的代码:

      import numpy as np
      import matplotlib.pyplot as plt
      x = np.arange(0, 3 * np.pi, 0.1)
      y = np.sin(x)
      plt.plot(x, y)
      plt.show()
      

      工作正常.. 它给了我这样的输出:

      所以,可能问题出在您的版本上,此外,根据您的错误,您的numpy package 似乎没有正确安装。安装 numpy 包,然后再次运行您的代码。 也添加matplotlib.pyplot 代替或仅添加matplotlib

      还要检查这个:Matplotlib, Pylab, Pyplot, etc: What's the difference between these and when to use each?

      希望对您有所帮助! :)

      【讨论】:

        猜你喜欢
        • 2016-01-24
        • 2018-08-07
        • 2019-04-07
        • 1970-01-01
        • 2013-10-26
        • 1970-01-01
        • 2015-10-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多