-2
import matplotlib.pyplot as plt    
import numpy as np

a=np.arange(1,11) 
b=np.arange(1,6)    
c=zip(a,b)    
d=list(c)

for e in d:   
    plt.scatter(e[0],e[1])

I want to plot these points on the same plot like this:

Community
  • 1
  • 1
Ashish Roy
  • 7
  • 1
  • 1

2 Answers2

0

This can easily be accomplished using the plot command, which takes a format string as third argument. Use o- for round markers joined with a solid line.

import matplotlib.pyplot as plt
import numpy as np

a = np.arange(1, 6)  b = np.arange(1, 6)    

plt.plot(a, b, 'o-')
MaxPowers
  • 5,235
  • 2
  • 44
  • 69
0

You have two options, depending what exactly you want. If you want all the points to have the same color as the line, you can use the method suggested by MaxPowers:

x = [i[0] for i in d]
y = [i[1] for i in d]
plt.plot(x, y, 'o-')

If you want to keep the points with different colors, and link them by a line, you can combine the two methods:

for e in d:   
    plt.scatter(e[0],e[1])
x = [i[0] for i in d]
y = [i[1] for i in d]
plt.plot(x, y)
shayelk
  • 1,606
  • 1
  • 14
  • 32