python 具有不同线宽的Pyplot网格

evrscar2  于 2023-01-01  发布在  Python
关注(0)|答案(1)|浏览(114)

我想用pyplot显示一个不同线宽的网格,上下文如下:
单元格之间互不连通,由不同厚度的壁分隔(有5种不同的壁厚)。I want it to look like this
谢谢你帮忙
我试过这个:

rows, cols = self.lignes, self.colonnes
fig, ax = plt.subplots(rows, cols,
                       sharex='col',
                       sharey='row')

for row in range(rows):
    for col in range(cols):
        ax[row, col].text(0.5, 0.5,
                          str((row, col)),
                          color="green",
                          fontsize=18,
                          ha='center')
        plt.axis('on')

plt.show()
rekjcdws

rekjcdws1#

我不确定你想如何为每个子图选择脊柱宽度,但这里有设置宽度的方法:

import matplotlib.pyplot as plt

rows, cols = 2, 3
fig, ax = plt.subplots(rows, cols,
                       sharex='col',
                       sharey='row')

for row in range(rows):
    for col in range(cols):
        spine_proxy = ax[row, col].spines[['top', 'bottom', 'left', 'right']]
        spine_proxy.set_linewidth(row*cols+col+1)
        ax[row, col].text(0.5, 0.5,
                          str((row, col)),
                          color="green",
                          fontsize=18,
                          ha='center')
        plt.axis('on')

plt.show()

有关Matplotib用于脊椎的API的详细信息,请参见docs

相关问题