pylab inside notebook

59 views
Skip to first unread message

Fabio Tonti

unread,
Apr 6, 2008, 4:45:34 PM4/6/08
to sage-s...@googlegroups.com
Hello everyone,

when I type pylab.imshow([[0]],interpolation='nearest') into the notebook, it doesn't show me anything. How can I plot matplotlib images inside the notebook? I'm sure there is a simple answer to this, I just couldn't find it...

Thanks in advance,
Fabioo

Michael

unread,
Apr 7, 2008, 7:22:19 PM4/7/08
to sage-support
See https://www.sagenb.org/home/pub/1463/

from pylab import *
plot([1,2,3,4])
savefig('foo.png')

Fabio Tonti

unread,
Apr 8, 2008, 7:34:13 AM4/8/08
to sage-s...@googlegroups.com
sage: from pylab import *
sage: imshow([[(0,0,0)]])
sage: savefig('foo.png')
Traceback (most recent call last):
...
NameError: global name 'npy' is not defined
I would just like to make an image from a 2-dimensional Array (of rgb-values)!

Carl Witty

unread,
Apr 12, 2008, 12:24:29 PM4/12/08
to sage-support
On Apr 8, 4:34 am, "Fabio Tonti" <fto...@gmail.com> wrote:
> sage: from pylab import *
> sage: imshow([[(0,0,0)]])
> sage: savefig('foo.png')
> Traceback (most recent call last):
> ...
> NameError: global name 'npy' is not defined
>
> I would just like to make an image from a 2-dimensional Array (of
> rgb-values)!

This is a bug in our current version of matplotlib; it is being
tracked here: http://trac.sagemath.org/sage_trac/ticket/2900

For now, it looks like you may be able to work around the problem by
using RGBA 4-tuples instead of RGB 3-tuples; that is, add an extra ",
255" on the end of each pixel.

You also need to be sure to use Python ints instead of Sage integers.
So with the commands:
sage: imshow([[(0r,0r,0r,255r)]])
sage: savefig('foo.png')
I at least don't get any more exceptions, and I do get a saved image.
However, I don't see a black pixel in the saved image, so it may not
actually be working.

Carl

Fabio Tonti

unread,
Apr 12, 2008, 1:10:50 PM4/12/08
to sage-s...@googlegroups.com
Thank you! Unfortunately I think you are also right with your last assumption. It just looks like an empty plot.
As a consequence, I tried this example with the new "knoboo" spkg, but here is what I get:

from pylab import *


Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/fabio/sage-2.11-debian32-intel-i686-Linux/local/lib/python2.5/site-packages/pylab.py", line 1, in <module>
    from matplotlib.pylab import *
  File "/home/fabio/sage-2.11-debian32-intel-i686-Linux/local/lib/python2.5/site-packages/matplotlib/pylab.py", line 197, in <module>
    from cbook import flatten, is_string_like, exception_to_str, popd, \
  File "/home/fabio/sage-2.11-debian32-intel-i686-Linux/local/lib/python2.5/site-packages/matplotlib/cbook.py", line 8, in <module>
    import numpy as npy
  File "/home/fabio/sage-2.11-debian32-intel-i686-Linux/local/lib/python2.5/site-packages/numpy/__init__.py", line 43, in <module>
    import linalg
  File "/home/fabio/sage-2.11-debian32-intel-i686-Linux/local/lib/python2.5/site-packages/numpy/linalg/__init__.py", line 4, in <module>
    from linalg import *
  File "/home/fabio/sage-2.11-debian32-intel-i686-Linux/local/lib/python2.5/site-packages/numpy/linalg/linalg.py", line 25, in <module>
    from numpy.linalg import lapack_lite
ImportError: liblapack.so: cannot open shared object file: No such file or


Should I open a new thread about this error? (I'm not sure how spkgs are handled)

Best wishes, Fabio

William Stein

unread,
Apr 12, 2008, 7:25:30 PM4/12/08
to sage-s...@googlegroups.com

NO. The Knoboo notebook is not yet supposed to actually work with anything
in the Sage library, beyond basic testing of Python code. I won't go into
why here, since I don't actually know. Rest assured that Dorian and Alex
and working on actually supporting using Sage functionality from knoboo...

-- William

Reply all
Reply to author
Forward
0 new messages