美文网首页
🤠 Merry Xmas | 用Matplotlib画个3D圣诞

🤠 Merry Xmas | 用Matplotlib画个3D圣诞

作者: 生信漫卷 | 来源:发表于2022-12-24 17:57 被阅读0次

    写在前面

    Merry Christmas ! 🥳

    过完圣诞就要跨年了,希望2023年自己可以一扫霉运,顺顺利利!!!😘

    从网上抄了个英文的祝福语送给大家(主要是懒): 👇

    I hope Santa is good to you this year because you only deserve the best🥰.


    今天就用pythonmatplotlib给大家画个圣诞树吧🎄。

    用到的包

    import math
    import matplotlib.pyplot as plt
    from matplotlib import animation
    from mpl_toolkits.mplot3d import Axes3D
    

    画个圣诞树🎄

    fig = plt.figure(figsize=(8,8))
    ax = fig.add_subplot(111, projection="3d")
    def init():
        k=300
        Z = [i for i in range(k)]
        X = [math.cos(i/5)*(k-i) for i in range(k)]
        Y = [math.sin(i/5)*(k-i) for i in range(k)]
        ax.scatter(X,Y,Z, c="green", marker="^")
        step = 3
        c = [(i/k,abs(0.5-i/k),i/k) for i in range(1,k,step)]
        Z = [i for i in range(1,k,step)]
        X = [math.cos(i/5+2)*(k-i+10) for i in range(1,k,step)]
        Y = [math.sin(i/5+2)*(k-i+10) for i in range(1,k,step)]
        ax.scatter(X,Y,Z, c=c, marker="o",s=40)
        plt.xlim(-500,500)
        plt.ylim(-500,500)
        return fig,
    def animate(f):
        fig.clear()
        ax = fig.add_subplot(111, projection="3d")
        k=300
        Z = [i for i in range(k)]
        X = [math.cos(i/5+f/10)*(k-i) for i in range(k)]
        Y = [math.sin(i/5+f/10)*(k-i) for i in range(k)]
        ax.scatter(X,Y,Z, c="green", marker="^")
        step = 3
        c = [(i/k,abs(0.5-i/k),i/k) for i in range(1,k,step)]
        Z = [i for i in range(1,k,step)]
        X = [math.cos(i/5+2+f/10)*(k-i+10) for i in range(1,k,step)]
        Y = [math.sin(i/5+2+f/10)*(k-i+10) for i in range(1,k,step)]
        ax.scatter(X,Y,Z, c=c, marker="o",s=40)
        plt.xlim(-500,500)
        plt.ylim(-500,500)
        return fig,
    ani=animation.FuncAnimation(fig, animate, init_func=init,
                                   frames=90, interval=50, blit=True)
    

    Note! 是有动画的哦,这里就不展示了,大家有兴趣试一下。🤪


    <img src="https://img.haomeiwen.com/i24475539/38c9ab841e311649.png" alt="矿泉水" style="zoom:25%;" />

    <center>最后祝大家圣诞快乐!~</center>


    点个在看吧各位~ ✐.ɴɪᴄᴇ ᴅᴀʏ 〰

    <center> <b>📍 往期精彩 <b> </center>

    📍 <font size=1>🤩 ComplexHeatmap | 颜狗写的高颜值热图代码!</font>
    📍 <font size=1>🤥 ComplexHeatmap | 你的热图注释还挤在一起看不清吗!?</font>
    📍 <font size=1>🤨 Google | 谷歌翻译崩了我们怎么办!?(附完美解决方案)</font>
    📍 <font size=1>🤩 scRNA-seq | 吐血整理的单细胞入门教程</font>
    📍 <font size=1>🤣 NetworkD3 | 让我们一起画个动态的桑基图吧~</font>
    📍 <font size=1>🤩 RColorBrewer | 再多的配色也能轻松搞定!~</font>
    📍 <font size=1>🧐 rms | 批量完成你的线性回归</font>
    📍 <font size=1>🤩 CMplot | 完美复刻Nature上的曼哈顿图</font>
    📍 <font size=1>🤠 Network | 高颜值动态网络可视化工具</font>
    📍 <font size=1>🤗 boxjitter | 完美复刻Nature上的高颜值统计图</font>
    📍 <font size=1>🤫 linkET | 完美解决ggcor安装失败方案(附教程)</font>
    📍 <font size=1>......</font>

    本文由mdnice多平台发布

    相关文章

      网友评论

          本文标题:🤠 Merry Xmas | 用Matplotlib画个3D圣诞

          本文链接:https://www.haomeiwen.com/subject/nicwqdtx.html