Reputation: 9054
import random
import math
import matplotlib.pyplot as plt
def circle():
x = []
y = []
for i in range(0,1000):
angle = random.uniform(0,1)*(math.pi*2)
x.append(math.cos(angle));
y.append(math.sin(angle));
plt.scatter(x,y)
plt.show()
circle()
I've written the above code to draw 1000 points randomly on a unit circle. However, when I run this code, it draws an oval for some reason. Why is this?
Upvotes: 9
Views: 5733
Reputation: 61
You can just set figure size:
def circle():
x = []
y = []
for i in range(0,1000):
angle = random.uniform(0,1)*(math.pi*2)
x.append(math.cos(angle));
y.append(math.sin(angle));
plt.figure(figsize=(5,5))
plt.scatter(x,y)
plt.show()
circle()
Upvotes: 0