Sorry, I'm a beginner and have no clue about plotting. I have four points: a, b, c and d. How do I plot them using matplotlib?
a = [1, 2]
b = [2, 4]
c = [2.5, 4]
d = [4.5, 5]
Thanks for your help!
The accepted answer is perfectly correct. Another possible way that I personally find a little cleaner would be to use Numpy to transpose the datapoints.
import numpy as np
import matplotlib.pyplot as plt
a = [1, 2]
b = [2, 4]
c = [2.5, 4]
d = [4.5, 5]
l = np.array([a,b,c,d]) #[[1,2], [2,4], [2.5,4], [4.5,5]]
datapoints = l.T #[[1, 2, 2.5, 4.5], [2, 4, 4, 5]]
plt.scatter(datapoints[0], datapoints[1])
plt.show()
Even cleaner than this would be to do
x,y = l.T
plt.scatter(x, y)
plt.scatter():import matplotlib.pyplot as plt
a = [1, 2]
b = [2, 4]
c = [2.5, 4]
d = [4.5, 5]
l = [a,b,c,d]
plt.scatter([i[0] for i in l], [i[1] for i in l])
plt.show()
Output: