如何减少matptolib中两个条之间的间距?

2024-04-20 04:48:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用matplotlib。在那里图中只有两个条形图,但它们之间的空间很大。我试图减少和增加宽度,但只是改变了条形图的宽度。你知道吗

def evaluate_bar_graph(coherences, indices):

        assert len(coherences) == len(indices)
        n = len(coherences)
        x = np.arange(n)
        plt.bar(x, coherences, width=0.1, tick_label=indices, align='center')
        plt.xlabel('Models')
        plt.ylabel('Coherence Value')
        plt.show()

enter image description here


Tags: len宽度matplotlibdefnpbar空间plt
1条回答
网友
1楼 · 发布于 2024-04-20 04:48:22

你可以用y位置选择你的条的位置,然后重命名x轴。 比如:

# space= 1 or 2

y_pos = [0, 1] # or y_pos = [0, 1]

# Create bars
plt.bar(y_pos, coherences)

# Create names on the x-axis
plt.xticks(y_pos, x)

# Show graphic
plt.show()

相关问题 更多 >