Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.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,我不知道如何控制下面代码中的条间距,从文件中读取数据。是否有任何方法可以调整/调整钢筋之间的间距(而不是钢筋宽度) 输入文件: 1450 25000 3000人 44000 51000 65000 如果条形宽度是固定的,并且您想要更改条形之间的间隙,唯一的方法是更改图形的宽度,这是您想要的吗?或者增加x范围-plt.xlim(0+0.5,10-0.5)间隙由条形宽度和x轴记号或点确定:间隙=(x2-x1)-宽度更改图形的宽度和增加x范围没有帮助。 #!/usr/bin/python import

我不知道如何控制下面代码中的条间距,从文件中读取数据。是否有任何方法可以调整/调整钢筋之间的间距(而不是钢筋宽度)

输入文件

1450
25000
3000人
44000
51000
65000


如果条形宽度是固定的,并且您想要更改条形之间的间隙,唯一的方法是更改图形的宽度,这是您想要的吗?或者增加x范围-
plt.xlim(0+0.5,10-0.5)
间隙由条形宽度和x轴记号或点确定:间隙=(x2-x1)-宽度更改图形的宽度和增加x范围没有帮助。
#!/usr/bin/python
import numpy as np
import pylab as plot
import matplotlib.pyplot as plt
import numpy, scipy, pylab, random
from matplotlib.ticker import MultipleLocator
import matplotlib as mpl
from matplotlib.ticker import MaxNLocator


with open("file.txt", "r") as f:
    x=[]
    y=[]
    for line in f:
        if not line.strip() or line.startswith('@') or line.startswith('#'): continue
        row = line.split()
        x.append(float(row[0]))
        y.append(float(row[1]))


fig = plt.figure(figsize=(3,2))
ax = plt.subplot(111)


plt.ylim(0, 6000)
ax.yaxis.set_major_locator(MaxNLocator(6))
ax.yaxis.set_minor_locator(MultipleLocator(500))
plt.xlim(0+0.5, 7-0.5)


bars=plt.bar(x,y, width=0.2, color='blue', edgecolor='black', align='center', linewidth=0.5)

bars[0].set_facecolor('gray')
bars[1].set_facecolor('orange')
bars[2].set_facecolor('green')
bars[3].set_facecolor('yellow')
bars[4].set_facecolor('cyan')
bars[5].set_facecolor('deeppink')


labels=['A', 'B', 'C', 'D', 'E', 'F']
plt.xticks(x, labels, rotation='45', rotation_mode='anchor', ha='right')

plt.ylabel('Values (m)', fontsize=7)

for axis in ['top','bottom','left','right']:
  ax.spines[axis].set_linewidth(0.5)

plt.subplots_adjust(top=0.97)
plt.subplots_adjust(bottom=0.05)
plt.subplots_adjust(left=0.07)
plt.subplots_adjust(right=0.98)


plt.tick_params(axis='both', which='major', labelsize=6)
plt.tick_params(axis='both', which='minor', labelsize=0)


plt.savefig("plot.png", dpi=300, bbox_inches='tight')