plot 2d lines by line equation in Python using Matplotlib
<p>Lets say I have 2d line equations (y = Ax + B) , i.e: </p>

<pre><code>[[A_1, B_1] , [A_2, B_2],  .. ]
</code></pre>

<p>and I want to plot the lines in 2d range, for example from point (-100,-100) to point (100,100).</p>

<p>as I understand the range limit can achieved with <code>xlim</code> and <code>ylim</code>, but I don't understand how to draw line according to its equation. I know that one way could be to find 2 points according the equation, but I don't understand how <code>plot</code> function works for my problem, Thanks.</p>

<p>To plot two straight lines within some specified range in x and y, you would do something like this:</p>

<pre><code>import numpy as np 
import matplotlib.pyplot as plt

A1,B1 = 1.,1.
A2,B2 = 2.,2.

x = np.linspace(-100.,100.)

fig,ax = plt.subplots()
ax.plot(x,A1*x+B1)
ax.plot(x,A2*x+B2)

ax.set_xlim((-100.,100.))
ax.set_ylim((-100.,100.))

plt.show()
</code></pre>

<p>Given that you phrased the question in terms of <code>[[A_1, B_1] , [A_2, B_2],  .. ]</code>, suggesting an array of different lines you'd like to plot, then you can plot using a <code>for</code> loop like this:</p>

<pre><code>import numpy as np 
import matplotlib.pyplot as plt

AB = np.random.randn(100,2) #create a random array of [[A1,B1],[A2,B2],...] as example

x = np.linspace(-100.,100.)

fig,ax = plt.subplots()
for ABi in AB:
    A,B = ABi
    ax.plot(x, A*x+B )

ax.set_xlim((-100.,100.))
ax.set_ylim((-100.,100.))

plt.show()
</code></pre>

python matplotlib