【问题标题】:Why plt.set_xlim is a list?为什么 plt.set_xlim 是一个列表?
【发布时间】:2015-10-15 12:52:58
【问题描述】:

我导入 matplotlib:

import matplotlib.pyplot as plt

然后,在某个时候我尝试这个:

plt.set_xlim(datetime.date(2011,1,1),datetime.date(2015,9,1))

结果我得到了这个:

TypeError: 'list' object is not callable

我的猜测是,我在某个时候重写了plt.xlim(或类似的东西)。所以,我尝试了

plt.clf()

它没有帮助。我仍然收到相同的错误消息。那么,有谁知道为什么plt.set_xlim 是一个列表以及如何处理它?

【问题讨论】:

  • 您是否将名称 plt 用于其他用途?
  • 不,但我(错误地)执行了plt.xlim = [d1, d2]plt.set_xlim = [d1, d2] 之类的东西。
  • 我无法从头开始重新启动所有内容,因为我正在使用 IPython 笔记本工作并且从头开始所有内容将意味着再次读取数据并且需要很多时间(我不希望松开)。
  • set_xlim 无论如何都不应该在 matplotlib.pyplot 的命名空间中(至少在我的版本 1.4.3 中不应该)。如果您已经覆盖了确实在该模块的命名空间中的xlim 函数,您仍然可以使用类matplotlib.pyplot.Axesset_xlim 方法。

标签: python matplotlib ipython ipython-notebook typeerror


【解决方案1】:

我也有同样的问题。显然xlim 必须由轴而不是绘图来设置。 这与一些 matplotlib 文档和示例相矛盾(例如,here

无论如何:

ax = plt.gca()
ax.set_xlim(your_xmin, your_xmax)

编辑:matplotlib 文档现在似乎已修复。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-13
    • 2011-01-09
    相关资源
    最近更新 更多