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

python画圣诞树代码解读_Python 圣诞树PythonDay2:ChristmasTreeLasttimeIwenttopickuparealChristmastreewaswithLittleCharles.Itwasareallybigtree,Ihavetoholditonthewayback.ThisyearIdon’thavearealtree,s…

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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/35355.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注