擅长:python、mysql、java
<p>你可能想得太多了。图中有两条线段:</p>
<ol>
<li>从(0,0)到(A,A')</li>
<li>从(A,A’)到(B,B’)</li>
</ol>
<p>你知道<code>A = 5</code>,<code>m = 1</code>,所以<code>A' = 5</code>。你也知道<code>B = 10</code>。鉴于<code>(B' - A') / (B - A) = 0.75</code>,我们有{<cd6>}。因此,可以按如下方式绘制图:</p>
<pre><code>from matplotlib import pyplot as plt
m0 = 1
m1 = 0.75
x0 = 0 # Intercept
x1 = 5 # A
x2 = 10 # B
y0 = 0 # Intercept
y1 = y0 + m0 * (x1 - x0) # A'
y2 = y1 + m1 * (x2 - x1) # B'
plt.plot([x0, x1, x2], [y0, y1, y2])
</code></pre>
<p>希望您能看到计算给定一组极限的y值的模式。结果如下:</p>
<p><a href="https://i.stack.imgur.com/o1iIM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/o1iIM.png" alt="enter image description here"/></a></p>
<p>现在假设您确实想使用向量化,原因很模糊。你需要预先计算所有的y值并绘制一次,否则你会得到奇怪的结果。以下是对原始代码的一些修改:</p>
^{pr2}$
<p><a href="https://i.stack.imgur.com/1afa7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1afa7.png" alt="enter image description here"/></a></p>