Matplotlib:如何获得子图的三角矩阵?

Ger*_*Ger 1 python matplotlib subplot

我想将一组子图分成三行,第一行有一个子图,第二行有两个,第三行有三个。我做了以下事情:

fig, axes = plt.subplots(figsize=(10, 10), sharex=True, sharey=True, ncols=3, nrows=3)
x = np.linspace(0, 10, 100)
for i in range(3):
    for j in range(0, i+1):
        axes[i, j].plot(x, np.sin((i+j) *x))
Run Code Online (Sandbox Code Playgroud)

因此我得到: 在此处输入图片说明

如何删除三个空地块?

Vla*_*lov 6

这个怎么样?

fig, axes = plt.subplots(figsize=(10, 10), sharex=True, sharey=True, ncols=3, nrows=3)
x = np.linspace(0, 10, 100)
for i in range(3):
    for j in range(3):
        if i<j:
            axes[i, j].axis('off')
        else:
            axes[i, j].plot(x, np.sin((i+j) *x))
Run Code Online (Sandbox Code Playgroud)

它似乎产生了你正在寻找的情节:

在此处输入图片说明