plot returns an error when given a callable class

34 views
Skip to first unread message

Alden

unread,
Dec 17, 2013, 5:48:47 PM12/17/13
to sage-s...@googlegroups.com
I wrote a class with a __call__ method, and I want to plot an instance of it using plot() in the sage notebook.  I run the commands:

import circle_homeo
import cyclic_order
h = circle_homeo.PSL2R_action(cyclic_order.CyclicOrder('abAB'))[0]

(this doesn't matter; all that should matter is that h is some callable class)

plot(h, xmin=0, xmax=1)

returns the error:

*****************************************
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_32.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("cGxvdChoLCB4bWluPTAsIHhtYXg9MSk="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpnBGA3K/___code___.py", line 3, in <module>
    exec compile(u'plot(h, xmin=_sage_const_0 , xmax=_sage_const_1 )
  File "", line 1, in <module>
    
  File "/home/akwalker/Documents/software/sage-5.3/local/lib/python2.7/site-packages/sage/misc/decorators.py", line 692, in wrapper
    return func(*args, **kwds)
  File "/home/akwalker/Documents/software/sage-5.3/local/lib/python2.7/site-packages/sage/misc/decorators.py", line 537, in wrapper
    return func(*args, **options)
  File "/home/akwalker/Documents/software/sage-5.3/local/lib/python2.7/site-packages/sage/plot/plot.py", line 1130, in plot
    G = _plot(funcs, (xmin, xmax), **kwds)
  File "/home/akwalker/Documents/software/sage-5.3/local/lib/python2.7/site-packages/sage/plot/plot.py", line 1236, in _plot
    funcs, ranges = setup_for_eval_on_grid(funcs, [xrange], options['plot_points'])
  File "/home/akwalker/Documents/software/sage-5.3/local/lib/python2.7/site-packages/sage/plot/misc.py", line 148, in setup_for_eval_on_grid
    return fast_float(funcs, *vars,**options), [tuple(range+[range_step]) for range,range_step in zip(ranges, range_steps)]
  File "fast_eval.pyx", line 1377, in sage.ext.fast_eval.fast_float (sage/ext/fast_eval.c:9718)
AttributeError: EquivariantRHomeo instance has no attribute '__float__'
*******************************************

However, if I do:

f = lambda x:h(x)
plot(f, xmin=0, xmax=1)

That works fine.  Is there something I need to do to the class to convince plot() to call it?


P Purkayastha

unread,
Dec 17, 2013, 6:36:34 PM12/17/13
to sage-s...@googlegroups.com
Does the patch here help: http://trac.sagemath.org/ticket/15030 ?
> --
> You received this message because you are subscribed to the Google
> Groups "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to sage-support...@googlegroups.com.
> To post to this group, send email to sage-s...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/groups/opt_out.

Alden

unread,
Dec 18, 2013, 12:38:41 PM12/18/13
to sage-s...@googlegroups.com
Given what the patch is supposed to do, it seems like it should fix it.  However, when I try to install the patch, I get the error "abort: failed to synchronize metadata for "sage/plot/plot.py".  Anyway, not a huge deal, so I guess I should just wait until the patch is integrated in sage 6.1.

P Purkayastha

unread,
Dec 18, 2013, 7:16:26 PM12/18/13
to sage-s...@googlegroups.com
For now, perhaps the workaround is to use

plot(lambda x: h(x)).show(xmin=0, xmax=1)

Note that xmin, xmax work properly only with show when xmax < xmin.
ymin, ymax work with both plot() and show() and is used to "zoom in" on
the rendered graph. This is ticket
http://trac.sagemath.org/ticket/13368

If you ever intend to flip a graph, then use the usual format instead of
xmin, xmax in the case xmax < xmin:
plot(lambda x: h(x), (x, 0, 1))
plot(lambda x: h(x), (x, 0, 1)).show(xmax=0, xmin=1)

- basu.
> > an email to sage-support...@googlegroups.com <javascript:>.
> > To post to this group, send email to sage-s...@googlegroups.com
> <javascript:>.
> <http://groups.google.com/group/sage-support>.
> > For more options, visit https://groups.google.com/groups/opt_out
> <https://groups.google.com/groups/opt_out>.
Reply all
Reply to author
Forward
0 new messages