0

I am facing the below error while plotting graph in 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

My code looks like this:

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

P.S. : I need to use only above values in variables

ojas
  • 247
  • 1
  • 4
  • 17

1 Answers1

3

I'm not convinced that you are passing the arguments you want to bar. The arguments are left and height and they are supposed to be sequences of the same length giving the position and height of the bars.

You are passing in 56 million positions to generate 56 million bars (no wonder you get a memory error). But you are only supplying two heights.

Maybe you want this:

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