• 大小: 2KB
    文件类型: .py
    金币: 1
    下载: 0 次
    发布日期: 2021-06-02
  • 语言: Python
  • 标签: python  画心  

资源简介

用python画一个立体的心,代码很简单,认真看看很快就会了,小白程序员必备zb图,可以给朋友秀一秀

资源截图

代码片段和文件信息

#!/usr/bin/env python3
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator FormatStrFormatter
import matplotlib.pyplot as plt
import numpy as np
 
 
def heart_3d(xyz):
 return (x**2+(9/4)*y**2+z**2-1)**3-x**2*z**3-(9/80)*y**2*z**3
 
 
def plot_implicit(fn bbox=(-1.5 1.5)):
 ‘‘‘ create a plot of an implicit function
 fn ...implicit function (plot where fn==0)
 bbox ..the xyand z limits of plotted interval‘‘‘
 xmin xmax ymin ymax zmin zmax = bbox*3
 fig = plt.figure()
 ax = fig.add_subplot(111 projection=‘3d‘)
 A = np.linspace(xmin xmax 100) # resolution of the contour
 B = np.linspace(xmin xmax 40) # number of slices
 A1 A2 = np.meshgrid(A A) # grid on which the contour is plotted
 
 for z in B: # plot contours in the XY 

评论

共有 条评论