# Oblique.py # M.Lampton UCB SSL 2016 import numpy as np import matplotlib.patches as patches import matplotlib.pyplot as plt # Set up the parameters of the square surface to plot NSIDE = 100 # samples per side of square XPEAK = 56.1 # x location of peak YPEAK = 66.2 # y location of peak ZPEAK = 88.0 # height of peak NOISE = 1.0 # rms noise in surface RHALF = 4.0 # radius of peak at half intensity SHELF = 5.0 # pedestal height above zero level FLOOR = -5.0 # floor of polygons # Define the surface and the mapping of {x,y,z} onto screen {h,v} coordinates def zfunc(x, y): if y==0 or y==NSIDE-1: return FLOOR r2 = ((x-XPEAK)**2 + (y-YPEAK)**2)/RHALF**2 r4 = r2**2 return SHELF + NOISE*np.random.normal() + ZPEAK/(1+r4) def getHoriz(x,y): return x+y def getVert(x,y,z): return -0.5*x + 0.5*y + z # All set. Do the plot fig = plt.figure() ax = fig.add_subplot(111) for x in range(0, NSIDE): vertices = np.zeros(shape=(NSIDE,2)) for y in range(0, NSIDE): vertices[y] = (getHoriz(x,y), getVert(x,y,zfunc(x,y))) poly = patches.Polygon(vertices, facecolor=(0.,0.,1.), edgecolor=(1.,1.,1)) ax.add_patch(poly) ax.set_xlim(-10, 210) ax.set_ylim(-70, 120) plt.show()