Skip to content

Instantly share code, notes, and snippets.

@GeraldineE
Forked from franktoffel/Python-Christmas-tree.py
Created December 16, 2018 07:01
Show Gist options
  • Save GeraldineE/03df03583c67d929477d97a33620aee6 to your computer and use it in GitHub Desktop.
Save GeraldineE/03df03583c67d929477d97a33620aee6 to your computer and use it in GitHub Desktop.

Revisions

  1. @franktoffel franktoffel revised this gist Dec 24, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Python-Christmas-tree.py
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@
    Author: Franz Navarro - CAChemE.org
    License: MIT
    Dependeces: Python, NumPy, matplotlib
    Dependencies: Python, NumPy, matplotlib
    """

    import matplotlib as mpl
  2. @franktoffel franktoffel revised this gist Dec 24, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Python-Christmas-tree.py
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # coding: utf-8
    """
    Draw a minimalist Christmas tree with Python and their awesome libaries.
    Draw a minimalist Christmas tree with Python and their awesome libraries.
    Code inspired by a StackEchange post and the Christmas spirit.
    http://codegolf.stackexchange.com/questions/15860/make-a-scalable-christmas-tree/16358#16358
  3. @franktoffel franktoffel created this gist Dec 24, 2014.
    41 changes: 41 additions & 0 deletions Python-Christmas-tree.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    # coding: utf-8
    """
    Draw a minimalist Christmas tree with Python and their awesome libaries.
    Code inspired by a StackEchange post and the Christmas spirit.
    http://codegolf.stackexchange.com/questions/15860/make-a-scalable-christmas-tree/16358#16358
    Author: Franz Navarro - CAChemE.org
    License: MIT
    Dependeces: Python, NumPy, matplotlib
    """

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

    # Calculate spiral coordinates for the Xmas tree
    theta = np.linspace(-8 * np.pi, 8 * np.pi, 200)
    z = np.linspace(-3, 0, 200)
    r = 5
    x = r * np.sin(theta)*z
    y = r * np.cos(theta)*z

    # Use matplotib and its OOP interface to draw it
    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

    # Plot the Xmas tree as a line
    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=250, marker='*')

    # Type here your best whishes
    ax.set_title(u"¡Feliz Navidad!")

    plt.show()