title: Can I define a regular polyline function in one line?(2)y=-x,y=x
body: <p>(ref)</p>
  <p><a href="https://stackoverflow.com/questions/71308739/can-i-define-a-regular-polyline-function-in-one-line">Can I define a regular polyline function in one line?(1)y=x,y=0</a></p>
  <p>(question)</p>
  <p><a href="https://i.stack.imgur.com/D9BcG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D9BcG.png" alt="enter image description here" /></a></p>
  <p>Can I define a line function in one line because it is regular?</p>
  <p>graph orenge line : myPoly</p>
  <p>Conditions :</p>
  <p>The image oscillates between Y=-x and Y=X.</p>
  <p>The slope of the line is 2 or -2.</p>
  <p>You can start with (2,0).</p>
  <p>y=-x,y=x</p>
  <p>Can this also be calculated using log?</p>
  <p>i try solve</p>
  <pre class="lang-py prettyprint-override"><code>    from sympy import *
      var('x y')
      import matplotlib.pyplot as plt
      def myPolyY(Ho, myX):
          myY = 0
          xx = [x[0] for x in Ho]
          yy = [x[1] for x in Ho]
          for i in range(len(xx) - 1):
              if xx[i] &lt;= myX &amp; myX &lt;= xx[i + 1]:
                 myY = (yy[i + 1] - yy[i]) / (xx[i + 1] - xx[i]) * (myX - xx[i]) + yy[i]
          return myY
      def myPolyDef(nMax):
          myPoly = [[0, 0], [2, 0]]
          i = 2
          ans = solve([y - x,
                       y - myPoly[i - 1][1] - 2 * (x - myPoly[i - 1][0])], [x, y])
          myPoly = myPoly + [[ans[x], ans[y]]]
          i = 1
          for j in range(nMax):
              i = i + 1
              ans = solve([y - (-x), y - myPoly[i][1] + 2 * (x - myPoly[i][0])], [x, y])
              myPoly = myPoly + [[ans[x], ans[y]]]
              i = i + 1
              ans = solve([y - x,
                           y - myPoly[i][1] - 2 * (x - myPoly[i][0])], [x, y])
              myPoly = myPoly + [[ans[x], ans[y]]]
          return myPoly
      def myPolyPlot(Ho, myLabel, myLinestyle):
          plt.plot([x[0] for x in Ho], [x[1] for x in Ho], mec='none', ms=4, lw=1, label=myLabel, linestyle=myLinestyle)
          for i in range(len(Ho)):
              if i % 2 == 0:
                  myPos = 'right'
              else:
                  myPos = 'left'
              plt.text(Ho[i][0], Ho[i][1], '({x}, {y})'.format(x=Ho[i][0], y=Ho[i][1]),
                       fontsize=6, horizontalalignment=myPos)
          return
      def myPolyNon(Ho, myLabel, myLinestyle):
          plt.plot([x[0] for x in Ho], [x[1] for x in Ho], mec='none', ms=4, lw=1, label='', linestyle='')
          return
      def main():
          # myN=4
          myN = 2
          myX = 200
          myPoly = myPolyDef(myN)
          myY = myPolyY(myPoly,myX)
          # matplotlib
          myH = max(list(map(lambda x: max(x), myPoly)))
          plt.axes().set_aspect('equal')
          plt.text(myX, myY, '({x}, {y})'.format(x=myX, y=myY),
                   fontsize=6, horizontalalignment='left')
          myPolyPlot([[myH, myH], [0, 0]], 'Y= X', '--')
          myPolyPlot(myPoly, 'myPoly', '-')
          myPolyPlot([[myH,-myH], [0, 0]], 'Y=-x', '--')
          myPolyNon ([[myH*2, -myH], [0, -myH]], '', '')
          plt.legend(frameon=False, fontsize=10, numpoints=1, loc='upper left')
          # plt.savefig('myPoly.png', dpi=200)
          plt.show()
      if __name__ == '__main__':
          main()
  
  </code></pre>