title: sympy matplolib piecewise TypeError?
body: <p>matplotlib TypeError? Please tell me the difference.</p>
  <p>i want to use plt.plot</p>
  <p>OK</p>
  <pre><code>from sympy import *
  from sympy.plotting import plot
  var('x')
  def main():
      p=Piecewise((0, x &lt; 2), (2 * x - 4, x &lt;= 4), (12 - 2 * x, x &lt;= 6), (2 * x - 12, x &lt;= 12), (36 - 2 * x, x &lt;= 18),
                  (2 * x - 36, x &lt;= 36))
      plot(p)
  if __name__ == '__main__':
      main()
  </code></pre>
  <p>Error.why?</p>
  <pre><code>from sympy import *
  import matplotlib.pyplot as plt
  var('x')
  def main():
      p=Piecewise((0, x &lt; 2), (2 * x - 4, x &lt;= 4), (12 - 2 * x, x &lt;= 6), (2 * x - 12, x &lt;= 12), (36 - 2 * x, x &lt;= 18),
                  (2 * x - 36, x &lt;= 36))
      plt.plot(p)
      # plt.show()
  if __name__ == '__main__':
      main()
  </code></pre>
  <p>raise TypeError(&quot;can't convert expression to float&quot;)
  TypeError: can't convert expression to float</p>
  <p>(ref)</p>
  <p><a href="https://stackoverflow.com/questions/46187713/sympy-issues-with-plotting-a-piecewise-function">Sympy issues with plotting a piecewise function</a></p>
  <p><a href="https://stackoverflow.com/questions/71449150/sympy-piecewisehow-can-i-plot-a-piecewise-function-using-matplotlib">sympy piecewise:How can I plot a piecewise function using matplotlib?</a></p>
  <p>(20220315)</p>
  <p><a href="https://i.stack.imgur.com/16aep.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/16aep.png" alt="enter image description here" /></a></p>
  <pre><code>import sympy as sym
  import matplotlib.pyplot as plt
  import numpy as np
  x = sym.symbols('x')
  p = sym.Piecewise((      0,x&lt;= 2),
                    ( 2*x- 4,x&lt;= 4),
                    (-2*x+12,x&lt;= 6),
                    ( 2*x-12,x&lt;=12),
                    (-2*x+36,x&lt;=18),
                    ( 2*x-36,x&lt;=36)
                   )
  xvals = np.linspace(0, 36, 100)
  f = sym.lambdify(x, p)
  yvals = f(xvals)
  plt.plot(xvals, yvals)
  # plt.savefig('myPoly.png', dpi=200)
  plt.show()
  </code></pre>