In [2]:
%matplotlib inline
import numpy as np
from math import cos, sin
from matplotlib import pyplot
import matplotlib.pyplot as plt
angles=np.arange(0,6.28,1/10)
In [3]:
grid_pts=np.arange(-1,1,.07)
grid_pts=[(x,y) for x in grid_pts for y in grid_pts]
In [4]:
coords=[(cos(angle),sin(angle)) for angle in angles]
In [5]:
x_noise=np.random.random_sample(len(angles),)
y_noise=np.random.random_sample(len(angles),)
x_noise=[x/10 for x in x_noise]
y_noise=[y/10 for y in y_noise]
In [6]:
X=[coords[i][0]+x_noise[i] for i in range(len(angles))]
Y=[coords[i][1]+y_noise[i] for i in range(len(angles))]
In [7]:
plt.scatter(X,Y, s=1);
In [8]:
for i in range(len(angles)):
for j in range(i,len(angles)):
if (((((X[i]-X[j])**2)+((Y[i]-Y[j])**2))**(1/2))<0.3): #This is the 1D plot
pyplot.plot([X[i], X[j]], [Y[i], Y[j]], color='black') #This is the 1D plot
In [9]:
for i in range(len(angles)):
for j in range(i,len(angles)):
if (((((X[i]-X[j])**2)+((Y[i]-Y[j])**2))**(1/2))<0.3): #This is the 1D plot
pyplot.plot([X[i], X[j]], [Y[i], Y[j]], color='black') #This is the 1D plot
for k in range(j,len(angles)):#This is the 2D plot
for point in grid_pts: #We check if the grid point is within 0.15 of all three given points.
if (((((point[0]-X[i])**2)+((point[1]-Y[i])**2))**(1/2))<0.15) and \
(((((point[0]-X[j])**2)+((point[1]-Y[j])**2))**(1/2))<0.15) and \
(((((point[0]-X[k])**2)+((point[1]-Y[k])**2))**(1/2))<0.15):#If so, we fill in the corr. triangle
plt.fill((X[i],X[j],X[k]),(Y[i],Y[j],Y[k]), color='blue')
In [10]:
for i in range(len(angles)):
for j in range(i,len(angles)):
if (((((X[i]-X[j])**2)+((Y[i]-Y[j])**2))**(1/2))<0.4): #This is the 1D plot
pyplot.plot([X[i], X[j]], [Y[i], Y[j]], color='black') #This is the 1D plot
for k in range(j,len(angles)):#This is the 2D plot
for point in grid_pts: #We check if the grid point is within 0.08 of all three given points.
if (((((point[0]-X[i])**2)+((point[1]-Y[i])**2))**(1/2))<0.2) and \
(((((point[0]-X[j])**2)+((point[1]-Y[j])**2))**(1/2))<0.2) and \
(((((point[0]-X[k])**2)+((point[1]-Y[k])**2))**(1/2))<0.2):#If so, we fill in the corr. triangle
plt.fill((X[i],X[j],X[k]),(Y[i],Y[j],Y[k]), color='blue')
It would be nice to run this on a larger collection of points, but the way I have written the code, the computation explodes quickly. For visualization's sake, here's what the first two steps would look like with a larger sample size.
In [11]:
angles=np.arange(0,6.28,1/100)
In [12]:
coords=[(cos(angle),sin(angle)) for angle in angles]
x_noise=np.random.random_sample(len(angles),)
y_noise=np.random.random_sample(len(angles),)
x_noise=[x/10 for x in x_noise]
y_noise=[y/10 for y in y_noise]
X=[coords[i][0]+x_noise[i] for i in range(len(angles))]
Y=[coords[i][1]+y_noise[i] for i in range(len(angles))]
plt.scatter(X,Y, s=1);
In [13]:
for i in range(len(angles)):
for j in range(len(angles)):
if (((((X[i]-X[j])**2)+((Y[i]-Y[j])**2))**(1/2))<0.06):
pyplot.plot([X[i], X[j]], [Y[i], Y[j]], color='black')
In [ ]: