title: Draw horizontal and vertical tangents
body: <p>The standard code for plotting lines from a point would be something like the following:</p>
  <pre><code>import numpy as np
  from matplotlib import pyplot as plt
  
  def plot_tangents(x, y, tangents):
      plt.plot(x, y, 'b.')
      # set xlim/ylim
      plt.xlim([min(x)-50, max(x)+50])
      plt.ylim([min(y)-50, max(y)+50])
  
      for i, m in enumerate(tangents):
          tx = np.linspace(x[i] - 5, x[i] + 5)
          plt.plot(tx, m*(tx - x[i]) + y[i], 'r--', label=f&quot;y={m}(x - {x[i]} + {y[i]}&quot;)
          
      plt.show()
  
  # Working example
  dummyx = np.linspace(50, 100)
  dummyy = np.linspace(50, 100)
  dummym = np.linspace(1, 1)
  plot_tangents(dummyx, dummyy, dummym)
  
  # Failing example
  dummyx = np.linspace(50, 50)
  dummyy = np.linspace(200, 550)
  dummym = np.array([np.inf] * 50)
  plot_tangents(dummyx, dummyy, dummym)
  </code></pre>
  <p>However when given vertical lines with linspace in x or horizontal lines with linspace in y, this code will fail to plot.</p>
  <p>Is there anyway to get matplot to handle these cases - ideally I'd like to plot a limited segment length for the tangent rather than an x/y range.</p>
  <p><a href="https://i.stack.imgur.com/UZV7B.png" rel="nofollow noreferrer">Expected tangents forming the line</a></p>
  <p><a href="https://i.stack.imgur.com/Cf4Mj.png" rel="nofollow noreferrer">Missing vertical line, no plot visible (which makes sense from the equation)</a></p>
  <p><strong>Partial Solution</strong></p>
  <p>The missing vertical line can be fixed with the following change to the line plot code - thanks @tdy - but understandably this is now an infinite line tangent.</p>
  <pre><code>plt.axline(xy1=(x[i], y[i]), slope=m, label=f'$y {-y[i]:+} = {m}(x {-x[i]:+})$')
  </code></pre>