继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

Python 圣诞树

乌然娅措
关注TA
已关注
手记 64
粉丝 22
获赞 12

Python Day 2: Christmas Tree

Last time I went to pick up a real Christmas tree was with Little Charles. It was a really big tree, I have to hold it on the way back.

This year I don’t have a real tree, so I made a Christmas tree with Python.

image

Code:

import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt

theta = np.linspace(-8 * np.pi, 8 * np.pi, 300) 
z = np.linspace(-3, 0, 300)
r = 8
x = r * np.sin(theta)*z
y = r * np.cos(theta)*z

fig = plt.figure() # Create figure
ax = fig.gca(projection='3d') # It's a 3D Xmas tree!
ax.view_init(15, 0) # Set a nice view angle
ax._axis3don = False # Hide the 3d axes

ax.plot(x, y, z,
        c='green', linewidth=2.5)

# Every Xmas tree needs a star
ax.scatter(0, 0, 0.2,
           c='red', s=300, marker='*')

# Type here your best whishes
ax.set_title("Merry Christmas !")
plt.show()

Happy Studying! 🎁

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP