Ask Your Question

Revision history [back]

This is because it first evaluates myfn2(x) on the symbolic variable x, and the test x < 0 then returns False, so what gets plotted is only -1.

The workaround is this:

sage: def myfn2(x):
....:     if x < 0:
....:         return 1
....:     else:
....:         return -1
....:     
sage: plot(lambda x: myfn2(x), (-3, 3), figsize=3, color='red')