density_plot + def'ed python function = TypeError?
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?