gpt4 book ai didi

python - Matplotlib : How to get a triangular matrix of subplots?

转载 作者:行者123 更新时间:2023-11-30 22:42:43 25 4
gpt4 key购买 nike

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

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))

因此我得到: enter image description here

如何删除三个空地 block ?

最佳答案

这个怎么样?

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))

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

enter image description here

关于python - Matplotlib : How to get a triangular matrix of subplots?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42038563/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com