'Plot a 3 line graphs on a scatter plot_Python

I want to plot a 3 line plots on the scatter plot to check how much scatter are the points from the line plot My scatter plot is obtained as below

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()

Now, I want to plot another 3 line graphs on the scatter plot such that,

  1. 1 line graph @ x = y
  2. 2nd Line graph @ x = 10*y
  3. 3rd Line graph @ x = 10/y

Expected outout

enter image description here

Please help me how to do this in python



Solution 1:[1]

What you describe would be the following:

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()

But you are likely looking for 3 lines with similar slope but different intersection point so instead (more like in the drawing):

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')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mariusmarten