Le vendredi 3 janvier 2020 15:51:00 UTC+1, Donald Munro a écrit :
>
> Dima Pasechnik wrote:
>>
>> On Fri, Jan 3, 2020 at 8:52 PM Donald Munro <[email protected]> wrote: 
>> > 
>> > Running: 
>> >> 
>> >> from sage.plot.plot3d.shapes2 import Line 
>> >> X = Line([(-1, 0, 0), (0, 0, 0), (1, 0, 0)], color='red') 
>> >> Y = Line([(0, -1, 0), (0, 0, 0), (0, -1,0)], color='green') 
>> >> Z = Line([(0, 0, -1), (0, 0, 0), (0, 0, -1)], color='green') 
>> >> show(X+Y+Z, figsize=8) 
>> > 
>> > 
>> > results in a 
>> >> 
>> >> TypeError: Object of type Integer is not JSON serializable 
>>
>> the problem is that Sage's type Integer cannot be used in Line() 
>> You'd need to use Python types, e.g. int(), float(), etc 
>> E.g. 
>>
>> Line([(int(-1), int(0), int(0)), (int(0), int(0), int(0)), (int(1), 
>>
>> Thanks,  replacing the above code with 
>
>> def to_float(v):
>>     vv = [None] * len(v)
>>     for i in range(0, len(v)):
>>         vv[i] = float(v[i])
>>     return vv    
>> from sage.plot.plot3d.shapes2 import Line
>> X = Line([to_float((-1, 0, 0)), to_float((0, 0, 0)), to_float((1, 0, 
>> 0))], color='red')
>> Y = Line([to_float((0, -1, 0)), to_float((0, 0, 0)), to_float((0, 
>> -1,0))], color='green')
>> Z = Line([to_float((0, 0, -1)), to_float((0, 0, 0)), to_float((0, 0, 
>> -1))], color='green')
>> show(X+Y+Z, figsize=8)
>>
>  
>  does solve the problem  or at least provide a work-around.
>


A simpler workaround is to use `line3d` instead of `Line`:

sage: from sage.plot.plot3d.shapes2 import line3d
sage: X = line3d([(-1, 0, 0), (0, 0, 0), (1, 0, 0)], color='red')
sage: Y = line3d([(0, -1, 0), (0, 0, 0), (0, -1,0)], color='green')
sage: Z = line3d([(0, 0, -1), (0, 0, 0), (0, 0, -1)], color='green')
sage: G = X + Y + Z
sage: G.show(figsize=8) 

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/19a7242e-e595-4b55-8a45-0e7e00ac8fe4%40googlegroups.com.

Reply via email to