【问题标题】:Getting Error while using grid method in Python在 Python 中使用网格方法时出错
【发布时间】:2021-07-26 10:30:21
【问题描述】:

在 python 中使用 Matplotlib,我尝试了这段代码并得到了以下错误。请帮忙。

代码

plt.plot(x,y)
plt.grid(True)
plt.show()

错误

TypeError: 'bool' 对象不可调用

【问题讨论】:

  • 你需要向我们展示更多的代码,因为很明显你已经覆盖了一些东西。究竟是哪一行产生了这个错误?
  • 我认为这意味着plt 不是您认为的对象。但是如果不查看更多代码或不知道哪些行会产生此错误,则几乎无法分辨。 type(plt) 返回什么?
  • import numpy as np from matplotlib import pyplot as plt x = np.arange(1,11) y=2*x plt.plot(x,y) plt.grid(True) plt.show ()

标签: python matplotlib data-visualization


【解决方案1】:

您需要做的就是重新加载pyplot 模块。

from importlib import reload

reload(plt)

plt.grid(True)

【讨论】:

    【解决方案2】:

    你试过plt.grid()(没有True)吗?

    【讨论】:

    • 是的,但是没有用。使用网格方法时似乎没有任何效果。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-16
    • 2023-03-08
    • 2020-04-30
    • 2012-01-13
    • 1970-01-01
    相关资源
    最近更新 更多