import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

"""
Explanation: Plotting $\sin(x^2+y^2)$ for a regular grid with a total of 40,000 points or 20,000 points and on 20,000 random points
We create (x,y) points first and plot a scatter plot on them with gray level given by $\sin(x^2+y^2)$
Importing vector and plotting libraries. %matplotlib inline to see plots in notebook
End of explanation
"""


xlist = np.arange(-10.0, 10.0, 0.1) # vector of x values
ylist = np.arange(-10.0, 10.0, 0.1) # vector of y values
X, Y = np.meshgrid(xlist, ylist) # regular mesh from x and y values

Z = np.sin(X**2 + Y**2) # function to plot

fig, axes = plt.subplots(figsize=(4,4)) # Making fig square
plt.title('Hi res regular grid')
plt.scatter(X, Y, c=Z, s=1) # Scatter plot
plt.gray()

"""
Explanation: First we show the case of a regular grid with a total of 40,000 points
We plot the function between -10 and 10, so for a total of 40,000 points we need a spacing of $0.1=20/\sqrt(40000)$ in a regular grid
End of explanation
"""


xlist = np.arange(-10.0, 10.0, 0.1414) # vector of x values
ylist = np.arange(-10.0, 10.0, 0.1414) # vector of y values
X, Y = np.meshgrid(xlist, ylist) # regular mesh from x and y values

Z = np.sin(X**2 + Y**2) # function to plot
fig, axes = plt.subplots(figsize=(4,4)) # Making fig square
plt.title('Lower res regular grid')

plt.scatter(X, Y, c=Z, s=1) # Scatter plot
plt.gray()


"""
Explanation: Already at this resolution above one can interference patterns. These patterns are more clear when using less points in the grid,
below for 20,000 points, for which the spacing is $0.1414=20/\sqrt(20000)$
End of explanation
"""


X = np.random.uniform(low=-10, high=10, size=(20000,))
Y= np.random.uniform(low=-10, high=10, size=(20000,))
Z = np.sin(X**2 + Y**2)
plt.figure()

fig, axes = plt.subplots(figsize=(4,4)) # Making fig square
plt.title('random points')
plt.scatter(X, Y, c=Z, s=1)
plt.gray()

"""
Explanation: Now for 20,000 random points
End of explanation
"""


