plot(f,(x,-1,2),adaptive=False, num_of_points=200)
 
this should work

On Friday, March 17, 2017 at 1:20:07 PM UTC-7, bonc...@udel.edu wrote:
>
> Plotting a Piecewise function fails.  I've pasted the markdown from my 
> ipython notebook:
>
> ```python
> from sympy import *
> init_session()
> ```
>
>     IPython console for SymPy 1.0 (Python 3.6.0-64-bit) (ground types: 
> python)
>     
>     These commands were executed:
>     >>> from __future__ import division
>     >>> from sympy import *
>     >>> x, y, z, t = symbols('x y z t')
>     >>> k, m, n = symbols('k m n', integer=True)
>     >>> f, g, h = symbols('f g h', cls=Function)
>     >>> init_printing()
>     
>     Documentation can be found at http://docs.sympy.org/1.0/
>
> ```python
> f = Piecewise((0,x<0), (1,x<1), (0,True))
> print(f.subs(x,-0.5), f.subs(x,0.5), f.subs(x,1.5))
> plot(f,(x,-1,2))
> ```
>
>     0 1 0
>
>
>
>     
> ---------------------------------------------------------------------------
>
>     TypeError                                 Traceback (most recent call 
> last)
>
>     
> /Users/boncelet/anaconda/lib/python3.6/site-packages/sympy/plotting/experimental_lambdify.py
>  
> in __call__(self, args)
>         193             #The result can be sympy.Float. Hence wrap it with 
> complex type.
>     --> 194             result = complex(self.lambda_func(args))
>         195             if abs(result.imag) > 1e-7 * abs(result):
>
>
>     
> /Users/boncelet/anaconda/lib/python3.6/site-packages/sympy/plotting/experimental_lambdify.py
>  
> in __call__(self, *args, **kwargs)
>         310     def __call__(self, *args, **kwargs):
>     --> 311         return self.lambda_func(*args, **kwargs)
>         312 
>
>
>     <string> in <lambda>(x0)
>
>
>     TypeError: '<' not supported between instances of 'complex' and 'int'
>
>     
>     During handling of the above exception, another exception occurred:
>
>
>     TypeError                                 Traceback (most recent call 
> last)
>
>     <ipython-input-2-447f720245d0> in <module>()
>           1 f = Piecewise((0,x<0), (1,x<1), (0,True))
>           2 print(f.subs(x,-0.5), f.subs(x,0.5), f.subs(x,1.5))
>     ----> 3 plot(f,(x,-1,2))
>     
>
>     
> /Users/boncelet/anaconda/lib/python3.6/site-packages/sympy/plotting/plot.py 
> in plot(*args, **kwargs)
>        1282     plots = Plot(*series, **kwargs)
>        1283     if show:
>     -> 1284         plots.show()
>        1285     return plots
>        1286 
>
>
>     
> /Users/boncelet/anaconda/lib/python3.6/site-packages/sympy/plotting/plot.py 
> in show(self)
>         183             self._backend.close()
>         184         self._backend = self.backend(self)
>     --> 185         self._backend.show()
>         186 
>         187     def save(self, path):
>
>
>     
> /Users/boncelet/anaconda/lib/python3.6/site-packages/sympy/plotting/plot.py 
> in show(self)
>        1016 
>        1017     def show(self):
>     -> 1018         self.process_series()
>        1019         #TODO after fixing 
> https://github.com/ipython/ipython/issues/1255
>        1020         # you can uncomment the next line and remove the 
> pyplot.show() call
>
>
>     
> /Users/boncelet/anaconda/lib/python3.6/site-packages/sympy/plotting/plot.py 
> in process_series(self)
>         895             # Create the collections
>         896             if s.is_2Dline:
>     --> 897                 collection = 
> self.LineCollection(s.get_segments())
>         898                 self.ax.add_collection(collection)
>         899             elif s.is_contour:
>
>
>     
> /Users/boncelet/anaconda/lib/python3.6/site-packages/sympy/plotting/plot.py 
> in get_segments(self)
>         501                     list_segments.append([p, q])
>         502 
>     --> 503             f_start = f(self.start)
>         504             f_end = f(self.end)
>         505             sample([self.start, f_start], [self.end, f_end], 0)
>
>
>     
> /Users/boncelet/anaconda/lib/python3.6/site-packages/sympy/plotting/experimental_lambdify.py
>  
> in __call__(self, args)
>         227                                                     
> use_evalf=True,
>         228                                                     
> complex_wrap_evalf=True)
>     --> 229                 result = self.lambda_func(args)
>         230                 warnings.warn('The evaluation of the 
> expression is'
>         231                         ' problematic. We are trying a 
> failback method'
>
>
>     
> /Users/boncelet/anaconda/lib/python3.6/site-packages/sympy/plotting/experimental_lambdify.py
>  
> in __call__(self, *args, **kwargs)
>         309 
>         310     def __call__(self, *args, **kwargs):
>     --> 311         return self.lambda_func(*args, **kwargs)
>         312 
>         313 
>
>
>     <string> in <lambda>(x0)
>
>
>     TypeError: '<' not supported between instances of 'complex' and 'int'
>
>
>
> ```python
>
> ```
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/46f2ee02-31e0-4259-8312-d8ea592aabfd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to