我正在使用 matplotlib制作级联图(这种风格的东西)。我想让我所有不同宽度的条相互齐平,但我希望底部的刻度从 1 到 7 定期增加,与条无关。但是,目前,它看起来像这样:
到目前为止,这就是我所拥有的:
python
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
n_groups = 6
name=['North America','Russia','Central & South America','China','Africa','India']
joules = [33.3, 21.8, 4.22, 9.04, 1.86, 2.14]
popn=[346,143,396,1347,1072,1241]
fig, ax = plt.subplots()
index = np.arange(n_groups)
bar_width = [0.346,.143,.396,1.34,1.07,1.24]
opacity = 0.4
rects1 = plt.bar(index+bar_width, joules, bar_width,
alpha=opacity,
color='b',
label='Countries')
def autolabel(rects):
# attach some text labels
for ii,rect in enumerate(rects):
height = rect.get_height()
ax.text(rect.get_x()+rect.get_width()/2., 1.05*height, '%s'%(name[ii]),
ha='center', va='bottom')
plt.xlabel('Population (millions)')
plt.ylabel('Joules/Capita (ten billions)')
plt.title('TPEC, World, 2012')
plt.xticks(1, ('1', '2', '3', '4', '5','6')
autolabel(rects1)
plt.tight_layout()
plt.show()
到目前为止,我尝试调整条间距的所有变化都导致了类似的问题。有任何想法吗?