Skip to content Skip to sidebar Skip to footer

Plot Lattice Tree In Python

I'm seeking ideas to plot a tuple tree t = ((4,), (3, 5,), (2, 4, 6,), (1, 3, 5, 7,)) as the following image (assuming this binomial tree size can change). I'm trying to avoid depe

Solution 1:

I'm using this piece of code which gives a pretty good result:

from matplotlib import pyplot as plt
import numpy as np

fig = plt.figure(figsize=[5, 5])
for i inrange(3):
    x = [1, 0, 1]
    for j inrange(i):
        x.append(0)
        x.append(1)
    x = np.array(x) + i
    y = np.arange(-(i+1), i+2)[::-1]
    plt.plot(x, y, 'bo-')
plt.show()

enter image description here

Post a Comment for "Plot Lattice Tree In Python"