Matplotlib 设置条形起始点值

Kou*_*nha 5 python matplotlib

我有一个数据集,我在 python 的 matplotlib 的帮助下绘制如下:

import matplotlib.pyplot as plt
%matplotlib inline

n_groups = 10
fig, ax = plt.subplots()
fig.set_size_inches(15,10)
index = np.arange(0, n_groups * 2, 2)
print index
bar_width = 0.35
opacity = 0.4
error_config = {'ecolor': '0.3'}

rects1 = plt.bar(index, df.Quant[0:10], bar_width,
                 alpha=opacity,
                 color='b',
                 error_kw=error_config,
                 label='Quant')

rects2 = plt.bar(index + bar_width, df.English[0:10], bar_width,
                 alpha=opacity,
                 color='r',
                 error_kw=error_config,
                 label='English')

rects3 = plt.bar(index + bar_width * 2, df.Logical[0:10], bar_width,
                 alpha=opacity,
                 color='g',
                 error_kw=error_config,
                 label='Logical')

plt.xlabel('Group')
plt.ylabel('Scores')
plt.title('Scores by Designation')
plt.xticks(index + bar_width, df.Designation[0:10], rotation='vertical')
plt.legend()

plt.tight_layout()
plt.show()
Run Code Online (Sandbox Code Playgroud)

结果如下图:

在此处输入图片说明

正如您所看到的,这些值相差 400 点以上。我如何将图表的范围从 400 缩小到更大?

另外,我试图在中做同样的事情,seaborn但找不到任何例子。

小智 4

使用ax.set(ylim=[400, 600])就会达到目的。这里,400 是 y 轴的最小值,600 是 y 轴的最大值。根据需要更改它。

我复制了你的图表的一部分,其中 y 轴被缩短了。 在此输入图像描述