python画圣诞树代码解读_Python 圣诞树

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.

AAffA0nNPuCLAAAAAElFTkSuQmCC

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! 🎁

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值