【问题标题】:Matplotlib : How to get a triangular matrix of subplots?Matplotlib:如何获得子图的三角矩阵?
【发布时间】:2017-02-04 09:15:07
【问题描述】:

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

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

因此我得到:

如何删除三个空地块?

【问题讨论】:

    标签: python matplotlib subplot


    【解决方案1】:

    这个怎么样?

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

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

    【讨论】:

    • 你知道如何取回顶轴的 xticks 吗?
    • @Ger 好吧,如果你禁用 sharex=True 你会得到所有的 xticks 标记。否则,您可以使用单个轴实例的set_ticklabels 方法。
    猜你喜欢
    • 2018-04-29
    • 1970-01-01
    • 2023-02-09
    • 2011-06-16
    • 1970-01-01
    • 2015-05-21
    • 1970-01-01
    • 1970-01-01
    • 2018-05-25
    相关资源
    最近更新 更多