答案 0 :(得分:0)
我认为您要么必须手动绘制内容,要么稍微调整条形图。一个快速的例子:
import numpy as np
import matplotlib.pylab as pl
def remove_ax():
ax=pl.gca()
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.set_xticks([])
ax.get_yaxis().tick_left()
names = ['Bill','John','Mark']
weight = [155,225,180]
age = [30,40,50]
dh = 0.8
yloc = np.arange(3)
pl.figure()
ax=pl.subplot(121)
remove_ax()
pl.title('Weight')
pl.barh(yloc-dh/2, weight, dh, alpha=0.4)
xloc = ax.get_xlim()[-1] - 0.05 * (ax.get_xlim()[-1] - ax.get_xlim()[0])
for i in range(len(weight)):
pl.text(xloc, yloc[i], '{}'.format(weight[i]), va='center', ha='right', size=18)
ax.set_yticks(yloc)
ax.set_yticklabels(names)
ax.tick_params(labelbottom='off')
ax=pl.subplot(122)
remove_ax()
pl.title('Age')
pl.barh(yloc-dh/2, age, dh, alpha=0.4)
xloc = ax.get_xlim()[-1] - 0.05 * (ax.get_xlim()[-1] - ax.get_xlim()[0])
for i in range(len(weight)):
pl.text(xloc, yloc[i], '{}'.format(age[i]), va='center', ha='right', size=18)
ax.set_yticks(yloc)
ax.tick_params(labelleft='off')
ax.tick_params(labelbottom='off')