猿问

如何用pyplot.barh()显示每个栏上栏的值?

如何用pyplot.barh()显示每个栏上栏的值?

我生成了条形图,如何在每个条形图上显示条形图的值?

目前情节:

我想要得到的:

https://img1.mukewang.com/5d56628c0001121724991700.png

我的代码:

import osimport numpy as npimport matplotlib.pyplot as plt

x = [u'INFO', u'CUISINE', u'TYPE_OF_PLACE', u'DRINK', u'PLACE', u'MEAL_TIME', u'DISH', u'NEIGHBOURHOOD']y = [160, 167, 137, 18, 120, 36, 155, 130]fig, ax = plt.subplots()    width = 0.75 # the width of the bars ind = np.arange(len(y))  # the x locations for the groupsax.barh(ind, y, width, color="blue")ax.set_yticks(ind+width/2)ax.set_yticklabels(x, minor=False)plt.title('title')plt.xlabel('x')plt.ylabel('y')      #plt.show()plt.savefig(os.path.join('test.png'), dpi=300, format='png', bbox_inches='tight') # use format='svg' or 'pdf' for vectorial pictures


犯罪嫌疑人X
浏览 4676回答 3
3回答
随时随地看视频慕课网APP

相关分类

Python
我要回答