Created
March 24, 2016 14:50
-
-
Save plantvsbirds/af111be74ebfa7d0f1a6 to your computer and use it in GitHub Desktop.
plot a crazy function using trigs and matplotlib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from mpl_toolkits.mplot3d import Axes3D | |
import mpl_toolkits.mplot3d as mp3d | |
from matplotlib import cm | |
from matplotlib.ticker import LinearLocator, FormatStrFormatter | |
import matplotlib.tri as mtri | |
steps = 90 | |
x = np.linspace(10,100,steps) | |
y = [] | |
z = [] | |
pnts = [[], [], []] | |
pnt_tuples = [] | |
#print(x) | |
#x = np.tile(x, (2, 1)) | |
for xvalue in x: | |
upperlim = np.sqrt(50*50+(200-xvalue)*(200-xvalue)) | |
for yvalue in np.linspace(50, upperlim, steps): | |
temp = yvalue*yvalue - 50*50 | |
if temp < 0: | |
continue | |
res = ((200 - xvalue) * np.sqrt(temp)) | |
if res == 0: | |
continue | |
else: | |
zvalue=yvalue/res | |
zvalue=zvalue/(xvalue * xvalue) | |
pnts[0].append(xvalue) | |
pnts[1].append(yvalue) | |
pnts[2].append(zvalue) | |
#t = (xvalue, yvalue, zvalue) | |
#pnt_tuples.append(t) | |
# 50, 51, 52, 5........ LIM | |
fig = plt.figure() | |
ax = fig.add_subplot(111, projection='3d') | |
print("point length ", len(pnts[0])) | |
#pnts[0], pnts[1] = np.meshgrid(pnts[0], pnts[1]) | |
#print("done meshgrid") | |
#np.savetxt("pnts0.csv", pnts[0], delimiter=",") | |
#np.savetxt("pnts1.csv", pnts[1], delimiter=",") | |
#np.savetxt("pnts2.csv", pnts[2], delimiter=",") | |
#ax.plot_wireframe(pnts[0], pnts[1], pnts[2],rstride=1, cstride=1, edgecolor='none') | |
#rstride=100, cstride=100, | |
#ax.plot_surface(pnts[0], pnts[1], pnts[2], rstride=100, cstride=100,linewidth=0, antialiased=False) | |
#face = mp3d.art3d.Poly3DCollection(pnt_tuples, alpha=0.5, linewidth=1) | |
tri = mtri.Triangulation(pnts[0], pnts[1]) | |
print(len(tri.triangles)) | |
ax.plot_trisurf(pnts[0], pnts[1], pnts[2], triangles=filter(lambda t: t[0] - t[1] < 120 , tri.triangles), cmap=plt.cm.Spectral, edgecolor='none') | |
#verts = [sorted(zip(pnts[0], pnts[1], pnts[2]), key=lambda pnt: -pnt[2])] | |
#face = mp3d.art3d.Poly3DCollection(verts, edgecolor='none') | |
#face.set_zsort("min") | |
#alpha = 0.5 | |
#face.set_color((0, 0, 1, alpha)) | |
#face.set_facecolor((0, 0, 1, alpha)) | |
#ax.add_collection3d(face) | |
#for angle in range(0, 360): | |
# ax.view_init(30, angle) | |
# plt.draw() | |
ax.auto_scale_xyz(pnts[0],pnts[1],pnts[2]) | |
ax.view_init(45, 35) | |
plt.draw() | |
plt.show() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment