Tuesday, December 10, 2019

Functions & Surfaces

function_plotting_py.ipynb
import numpy,pylab; from mpl_toolkits.mplot3d import Axes3D
from matplotlib.lines import Line2D
angle=numpy.linspace(0,2*numpy.pi,64); T1,T2=numpy.meshgrid(angle,angle)
X=numpy.cos(T1)*numpy.sin(T2); Y=numpy.sin(T1)*numpy.sin(T2); Z=numpy.cos(T2)
labels=['$x^2+y^2+z^2=4^2$',
        '$x=3\;cos(t_1)\;sin(t_2)$\n$y=3\;sin(t_1)\;sin(t_2)$\n$z=3\;cos(t_2)$',
        '$\\frac{x^2}{1^2}+\\frac{y^2}{2^2}+\\frac{z^2}{3^2}=1$']
colors=['#3636ff','#ff3636','#ff36ff']
fig=pylab.figure(figsize=(12,12)); ax=fig.add_subplot(111,projection='3d')
ax.plot_surface(4*X,4*Y,4*Z,color=colors[0],alpha=0.1)
ax.plot_surface(3*X,3*Y,3*Z,color=colors[1],alpha=0.1)
ax.plot_surface(1*X,2*Y,3*Z,cmap=pylab.cm.bwr_r,linewidth=1,
                antialiased=True,rstride=1,cstride=1)
fake2Dlines=[Line2D([0],[0],linestyle="none",c=c,marker='o'for c in colors]
ax.legend(fake2Dlines,labels,loc=9,fontsize=15); pylab.show()

No comments:

Post a Comment