Ask Your Question
2

density_plot + def'ed python function = TypeError?

asked 2015-01-27 13:32:24 -0500

mbogosian gravatar image

updated 2015-01-27 13:57:23 -0500

tmonteil gravatar image

I have the following functions:

var('a, b')

# This will work with both contour_plot and density_plot
f1(a, b) = 1 - b / a

# So will this
f2(a, b) = 1 - a / b

# This only works with contour_plot?!
def f12(a, b):
    if a - b < 0:
        return f1(a, b)
    else:
        return f2(a, b)

Obviously, f1 and f2 are symbolic functions, where f12 is a def'ed python function. Calling contour_plot works on all three. Calling density_plot works on f1 and f2, but raises a TypeError when called with f12, the def'ed python function.

I've created a project that has an interactive session demonstrating the problem.

Here's the trace:

Error in lines 1-1
Traceback (most recent call last):
  ...
  File "/projects/443a2a33-d145-4b63-893f-175543cc50c6/.sagemathcloud/sage_salvus.py", line 2306, in show
    show_2d_plot_using_matplotlib(obj, svg=svg, **kwds)
  File "/projects/443a2a33-d145-4b63-893f-175543cc50c6/.sagemathcloud/sage_salvus.py", line 2229, in show_2d_plot_using_matplotlib
    obj.save(t, **kwds)
  File "/usr/local/sage/sage-6.4/local/lib/python2.7/site-packages/sage/misc/decorators.py", line 471, in wrapper
    return func(*args, **kwds)
  File "/usr/local/sage/sage-6.4/local/lib/python2.7/site-packages/sage/plot/graphics.py", line 2972, in save
    figure = self.matplotlib(**options)
  File "/usr/local/sage/sage-6.4/local/lib/python2.7/site-packages/sage/plot/graphics.py", line 2418, in matplotlib
    g._render_on_subplot(subplot)
  File "/usr/local/sage/sage-6.4/local/lib/python2.7/site-packages/sage/plot/density_plot.py", line 146, in _render_on_subplot
    subplot.imshow(self.xy_data_array, origin='lower', cmap=cmap, extent=(x0,x1,y0,y1),  interpolation=options['interpolation'])
  File "/usr/local/sage/sage-6.4/local/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/axes.py", line 7300, in imshow
    im.set_data(X)
  File "/usr/local/sage/sage-6.4/local/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/image.py", line 425, in set_data
    raise TypeError("Image data can not convert to float")
TypeError: Image data can not convert to float

Am I asking density_plot to do something crazy here? If not, what am I doing wrong?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-01-27 13:56:41 -0500

tmonteil gravatar image

updated 2015-01-28 06:08:03 -0500

There is certainly something wrong with density_plot here, thanks for reporting. Without exploring further, you can define f12 as follows:

def f12(a, b):
    if a - b < 0:
        return RDF(f1(a, b))
    else:
        return RDF(f2(a, b))

This seems to work.

The problem is reported as trac ticket 17684.

edit flag offensive delete link more

Comments

If you open a ticket, please cc: me.

kcrisman gravatar imagekcrisman ( 2015-01-27 14:36:32 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-01-27 13:32:24 -0500

Seen: 421 times

Last updated: Jan 28 '15