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.

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()

The python code is inspired by https://gist.github.com/franktoffel/aea4329b760eb3e72f4d

Happy Studying! 🎁

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,452评论 0 10
  • 在这学期刚开始的这一个月,我们学校进行了研究性课题。每个学生都会选择自己喜欢的课题进行研究。而我选择了一个...
    明月高硕阅读 121评论 0 0
  • [正念] 正念是一种存在的模式,一种需要持续培养的存在方式。正念的训练会自然延伸到生活的每一个层面。 虽然正念易于...
    不要多愁善感阅读 154评论 0 0
  • pdd,想必英雄联盟的玩家都不陌生,曾经看我神威,无坚不摧到一炮四个pdd,以及lpl当时最强上单,这些标签也促使...
    安静and阅读 568评论 0 0
  • 来上海,每天真正和他聊聊天的时间只有班车上的那短短的半个小时。所以每天下班那一刻都会是我一天中最开心的时候。...
    锋利的刻刀阅读 496评论 1 0