-3

Hii experts i need to join the line between the points obtained using for loop .But only scatter plot(plt.scatter) is working not the plt.plot option in matplotlib

my prograamme is

import numpy as np
import matplotlib.pyplot as plt

f=np.arange(1,5,1)

for i in f:
    sum = 0
    for m in np.arange(1,6,1):
        x=((4.6)*(m*2)*(5)**2)*(i)/62
        print(x)

        sum += x
    print(i,sum)
    plt.scatter(i,sum)
plt.show()
    

1 Answers1

0

Try this :

import numpy as np
import matplotlib.pyplot as plt

f=np.arange(1,5,1)

x_values = []
y_values = []
for i in f:
    sum = 0
    for m in np.arange(1,6,1):
        x=((4.6)*(m*2)*(5)**2)*(i)/62
        
        sum += x
   
    #plt.scatter(i,sum)

    x_values.append(i)
    y_values.append(sum)


plt.plot(x_values, y_values, marker='o')
 
plt.show()
JacksonPro
  • 3,135
  • 2
  • 6
  • 29