在散点图上绘制 3 条折线图 plot_Python

Plot a 3 line graphs on a scatter plot_Python

我想在散点图上绘制 3 条线图,以检查线图中的点散布了多少 我得到的散点图如下

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

x = np.array([38420690,53439687,82878917,97448841])
y = np.array([47581627,12731149,3388697,911432])

plt.scatter(x,y)

plt.plot()
plt.show()

现在,我想在散点图上绘制另外 3 个折线图,这样,

  1. 1 折线图 @ x = y
  2. 第 2 个折线图 @ x = 10*y
  3. 第 3 条线图 @ x = 10/y

预计出局

请帮助我如何在 python

中执行此操作

您的描述如下:

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

x = np.array([38420690,53439687,82878917,97448841])
y = np.array([47581627,12731149,3388697,911432])

val = [0, 97448841*0.5, 97448841]

plt.scatter(x,y)
plt.plot(val, val, color='red')
plt.plot(val, [i*10 for i in val], color='blue')
plt.plot(val, [i*0.1 for i in val], color='black')
plt.plot()
plt.show()

但您可能正在寻找 3 条斜率相似但交点不同的直线(更像图中所示):

plt.plot(val, val, color='red')
plt.plot(val, [i+10000000 for i in val], color='blue')
plt.plot(val, [i-10000000 for i in val], color='black')

您可以使用 x 数组的最小值和最大值创建一个比方说 50 个点的 linspace,然后对其应用操作:

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

x = np.array([38420690,53439687,82878917,97448841])
y = np.array([47581627,12731149,3388697,911432])
min_x = min(x)
max_x = max(x)

newx = np.linspace(min_x, max_x, 50)
newy = newx 
plt.figure(figsize=(12, 8))
plt.scatter(x,y, label='scatter')
plt.plot(newx, newy, color='red', label='x=y') # x=y
plt.plot(newx, newy*10, color='blue', label='x=10*y') # x -> 10*y'
plt.plot(newx, 10/newy, color='black',label='x=10/y') # x -> 10/y

plt.legend()

plt.show()

这导致: