Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python matplotlib酒吧减少酒吧之间的差距_Python_Matplotlib - Fatal编程技术网

python matplotlib酒吧减少酒吧之间的差距

python matplotlib酒吧减少酒吧之间的差距,python,matplotlib,Python,Matplotlib,我有一个barh条形图,图中只有两条条形,但在绘制它们时,它们相距很远: import numpy as np import matplotlib.pyplot as plt labels = ('Out', 'In') bar_values = [5, 10] num_items = len(labels) width = 0.25 ind = np.arange(num_items) bar_width = 0.1 fig = plt.figure() ax = fig.add_sub

我有一个
barh
条形图,图中只有两条条形,但在绘制它们时,它们相距很远:

import numpy as np
import matplotlib.pyplot as plt

labels = ('Out', 'In')
bar_values = [5, 10]
num_items = len(labels)
width = 0.25
ind = np.arange(num_items)
bar_width = 0.1

fig = plt.figure()

ax = fig.add_subplot(111)

barlist = ax.barh(ind,
                bar_values,
                bar_width,
                align='edge',
                color='green')

barlist[0].set_color('mediumseagreen')
barlist[1].set_color('orangered')

ax.set_yticks(ind)
ax.set_yticklabels(labels)
ax.invert_yaxis()  # labels read top-to-bottom
ax.set_xlabel('Total')

plt.show()

有没有办法把铁条靠得更近?我已经尝试指定图形的大小,但这只会减小总体大小,对间隙大小没有影响…

您可以通过设置
bar\u width=0.6
或类似的值来增加条形的宽度,也可以减小图形的y范围,例如:

barlist = ax.barh([0.1, 0.3],
                bar_values,
                bar_width,
                align='edge',
                color='green')
ax.set_yticks([0.1, 0.3])
ax.set_yticklabels(labels)
与钢筋之间的距离相比,两者都应增加钢筋的宽度。