I want to plot a piecewise function, such as:
import sympy as sym
x = sym.symbols("x")
f = sym.Piecewise((-1, x < -1),
(x, sym.And(-1 <= x, x < 0)),
(x**2, sym.And(0 <= x, x < 1)),
(x**3, x >= 1))
sym.plotting.plot(f, (x, -3, 3))
However, when running this code, an exception was raised ...
AttributeError: 'BooleanFalse' object has no attribute 'evalf'
I think the problem may come from the two cases
sym.And(-1 <= x, x < 0)
and
sym.And(0 <= x, x < 1)
Here a python type 'bool' supposed, while the function 'evalf' can't convert the 'sympy' type 'BooleanFalse' into the python type 'bool'.
I wander how to deal with this problem, and is it possible to plot the piecewise functions without using the 'matplotlib' module?