from matplotlib import pyplot as plt from math import pi, sin, cos # parameters N = 500 angle_range_0 = 1.3*(2*pi) angle_decay_c = 1.0 angle_decay_e = 1.0 # sequence a = [0] for n in range(N): a.append(a[int(n-a[n]*(a[n]-1)/2)]+1) # tree tree = {0:[]} for n in range(N): tree[int(n-a[n]*(a[n]-1)/2)].append(n+1) tree[n+1] = [] # plot positions = [[0, 0] for i in range(len(a))] angles = [0 for i in range(len(a))] for i in range(len(tree)): if(len(tree[i]) == 0): continue level = a[i] angle_range = angle_range_0/(angle_decay_c*level**angle_decay_e+1) d_angle = angle_range/(len(tree[i])+1) angle = angles[i]-angle_range/2+d_angle for leaf in tree[i]: positions[leaf] = [positions[i][0]+cos(angle), positions[i][1]+sin(angle)] angles[leaf] = angle angle = angle+d_angle plt.plot([positions[i][0], positions[leaf][0]], [positions[i][1], positions[leaf][1]], 'k', linewidth=1/(level+1)**0.6, alpha=1/(level+1)**0.7) plt.axes().set_aspect('equal') plt.axes().axis('off') plt.margins(0.02, 0.02) plt.savefig("tree.pdf", bbox_inches='tight', pad_inches=0.0) plt.show()