问题
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 dependencies on non-core packages (just sticking to pandas, numpy, matplotlib, scikit, and such).
回答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 in range(3):
x = [1, 0, 1]
for j in range(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()
来源:https://stackoverflow.com/questions/33712179/plot-lattice-tree-in-python