79503298

Date: 2025-03-12 10:36:08
Score: 1
Natty:
Report link

If anyone is interested in how to create the polar plots from the generated gray codes, here is some code for completeness (thanks OP for an interesting exercise on numpy and gray codes). Set an oversampling for small bit counts to make the plot smooth.

enter image description here

def plot_gray_codes(gc, oversampling=1):
    import matplotlib.pyplot as plt
    fig, ax = plt.subplots(subplot_kw={'projection': 'polar'})
    
    # Set an oversampling factor to make the polar plot smoother for small bit counts
    gc = np.repeat(gc, oversampling, axis=0) if oversampling > 1 else gc
    for i, j in zip(*np.where(gc)):
        ax.fill_between([i * 2 * np.pi / gc.shape[0], (i + 1) * 2 * np.pi / gc.shape[0]], [j, j], [j+1, j+1], color='black')

    ax.set_aspect('equal')
    plt.axis('off')
    plt.tight_layout()
    plt.show()
Reasons:
  • Blacklisted phrase (0.5): thanks
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: André