Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IDLE and matplotlib

if I enter this code in Ipython notebook it works:

plt.scatter(x,y)

but if enter it in python IDLE then I get this error:

<matplotlib.collections.PathCollection object at 0x0000000007957908>

Do you have any idea why?

Thanks a lot.

like image 642
alexmulo Avatar asked Mar 18 '26 16:03

alexmulo


1 Answers

When you work with IPython in the pylab mode, drawing is automatic after you plot something with matplotlib. This is not the case when you work in idle where you have to plt.show your image:

Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information.
>>> from matplotlib import pyplot as plt
>>> x = [1,3,6,2]
>>> y = [4,6,7,8]
>>> plt.scatter(x,y)
<matplotlib.collections.PathCollection object at 0x0000000005A6B7B8>
>>> plt.show()

If you want to plot automatically with idle you can use the interactive mode:

>>> from matplotlib import pyplot as plt
>>> from matplotlib import interactive
>>> interactive(True)
>>> x = [1,3,6,2]
>>> y = [4,6,7,8]
>>> plt.scatter(x,y)
<matplotlib.collections.PathCollection object at 0x0000000005D11BA8>
(the figure is drawn)
like image 109
joaquin Avatar answered Mar 20 '26 06:03

joaquin