我是初学者,matplotlib我正在尝试绘制两个条形图。对于第二个图,xlabels 很好,但对于第一个图,我得到了 xlabels 作为列表,它也有 unicode 字符串格式。这是我的代码:def get_val_from_dict(objects, n): x = [] y = [] for k,v in objects.items(): probalities = float(v)/n cat = k x.append(cat) y.append(probalities) return x,ymy x,y列表具有以下两个数据文件的格式:[u'fast_food', u'school', u'bar', u'beauty', u'hairdresser', u'park', u'hotel', u'kiosk', u'pub', u'nightclub', u'supermarket', u'restaurant', u'bakery', u'pharmacy', u'doctors', u'fitness_centre', u'cafe', u'bank', u'clothes'][0.08, 0.03, 0.03, 0.01, 0.05, 0.03, 0.19, 0.12, 0.04, 0.01, 0.01, 0.25, 0.03, 0.01, 0.02, 0.02, 0.05, 0.01, 0.02][u'fast_food', u'school', u'bar', u'jewelry', u'beauty', u'hairdresser', u'shoes', u'park', u'museum', u'restaurant', u'kiosk', u'supermarket', u'pharmacy', u'bakery', u'greengrocer', u'cafe', u'bank', u'clothes'][0.03, 0.03, 0.03, 0.03, 0.03, 0.15, 0.03, 0.09, 0.03, 0.21, 0.06, 0.03, 0.03, 0.06, 0.03, 0.06, 0.06, 0.03]x_all = []y_all = []name_ = []for arg in sys.argv[1:]: reload(sys) sys.setdefaultencoding('utf-8') fp = open(arg) contents = fp.read() name = arg n, data = subsamples(contents) x, y = get_val_from_dict(data, n) x_all.append(x) y_all.append(y) name_.append(name)count=0for i in range(len(x_all)): count += 1f, axarr = plt.subplots(count, sharex='col', sharey='row')for i in range(len(x_all)): axarr[i].set_title(label ="%s" %(name_[i])) axarr[i].bar(x_all[i], y_all[i]) axarr[i].tick_params(axis='both', which='both') axarr[i].set_xlabel(x) axarr[i].set_xticklabels(x_all[i], rotation=90)plt.show()如何将第一个子图绘制为下面的图?
添加回答
举报
0/150
提交
取消