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

1
  • Can you use xrange instead of range? Commented Dec 11, 2015 at 11:26

1 Answer 1

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.