【问题标题】:Python: Memory Error while using MatplotLibPython:使用 MatplotLib 时出现内存错误
【发布时间】:2015-12-11 11:25:28
【问题描述】:

我在 matplotlibFile 中绘制图形时遇到以下错误“

<stdin>", line 1, in <module>
  File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 2515, in bar
    ret = ax.bar(left, height, width=width, bottom=bottom, **kwargs)
  File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 4951, in bar
    width *= nbars
MemoryError

我的代码如下所示:

import matplotlib.pyplot as plt
x = [56508490, 56508490]
max = 56508490
plt.bar(range(0,max), x)  #-> error line
#plt.show()

附: :我只需要在变量中使用上述值

【问题讨论】:

  • 你能用 xrange 代替 range 吗?

标签: python matplotlib matplotlib-widget


【解决方案1】:

我不相信你正在将你想要的参数传递给bar。参数是leftheight,它们应该是相同长度的序列,给出了条形的位置和高度。

您传入 5600 万个仓位以生成 5600 万根柱线(难怪您会出现内存错误)。但是你只提供了两个高度。

也许你想要这个:

import matplotlib.pyplot as plt
x = [56508490, 56508490]
max = 56508490
plt.bar([0,1], x)  #-> error line
plt.show()

【讨论】:

    猜你喜欢
    • 2015-06-10
    • 2020-04-13
    • 2016-08-16
    • 1970-01-01
    • 1970-01-01
    • 2019-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多