简体   繁体   English

如何将代码自动化到 plot 两点之间的一条线?

[英]How can I automate code to plot a line between two points?

Currently trying to create an automated function that can find a line between two points.目前正在尝试创建一个自动化的 function,它可以找到两点之间的一条线。 Tried testing this function (by plotting) but when I plot the function I get a 'v-shaped' line.尝试测试此 function(通过绘图)但是当我 plot function 我得到一条“v 形”线。 What changes can I make to complete this function?我可以进行哪些更改来完成此 function? Thanks.谢谢。

     import matplotlib.pyplot as plt
     from math import e

     x = [0, 9]
     y = [7, 2]
     m = (y[1]-x[1])/(y[0]-x[0])
     b = m*(y[0]-x[0])+x[1]

     for i in range (-10, 10):
      prob_x = m*i + b

      x.append(i)
      y.append(prob_x)

     plt.plot(x,y)
import matplotlib.pyplot as plt

x = [0, 9]
y = [7, 2]
plt.plot(x, y)
plt.show()

You don't need to do anything, plt.plot returns a line between two points anyway你不需要做任何事情,plt.plot 无论如何都会返回两点之间的线

Output: Output:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM