Skip to content

Instantly share code, notes, and snippets.

@makokal
Created October 8, 2013 12:19
Show Gist options
  • Select an option

  • Save makokal/6883810 to your computer and use it in GitHub Desktop.

Select an option

Save makokal/6883810 to your computer and use it in GitHub Desktop.

Revisions

  1. makokal created this gist Oct 8, 2013.
    26 changes: 26 additions & 0 deletions circle_random.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    # generate random points in a circle

    import numpy as np
    import pylab as plt


    num_samples = 1000

    # make a simple unit circle
    theta = np.linspace(0, 2*np.pi, num_samples)
    a, b = 1 * np.cos(theta), 1 * np.sin(theta)

    # generate the points
    # theta = np.random.rand((num_samples)) * (2 * np.pi)
    r = np.random.rand((num_samples))
    x, y = r * np.cos(theta), r * np.sin(theta)

    # plots
    plt.figure(figsize=(7,6))
    plt.plot(a, b, linestyle='-', linewidth=2, label='Circle')
    plt.plot(x, y, marker='o', linestyle='.', label='Samples')
    plt.ylim([-1.5,1.5])
    plt.xlim([-1.5,1.5])
    plt.grid()
    plt.legend(loc='upper right')
    plt.show(block=True)