Python 熊猫图(条形图)非数值数据

Python 熊猫图(条形图)非数值数据,python,pandas,matplotlib,plot,Python,Pandas,Matplotlib,Plot,我有一系列数据(攀岩路线及其等级) 路线 等级 简易路线 9a+ 艰苦的 6c 另一条路线 7b+ 我建议首先添加等级的数字表示,以便在打印时保持顺序。之后,您可以手动将等级名称设置为yticklabels: 从matplotlib导入pyplot作为plt 作为pd进口熊猫 #以身作则 df=pd.DataFrame({'route':['Easy route','The hard','other route'],'grade':['9a+','6c','7b+']}) #原始等级 等级=['

我有一系列数据(攀岩路线及其等级)

路线 等级 简易路线 9a+ 艰苦的 6c 另一条路线 7b+
我建议首先添加等级的数字表示,以便在打印时保持顺序。之后,您可以手动将等级名称设置为
yticklabels

从matplotlib导入pyplot作为plt
作为pd进口熊猫
#以身作则
df=pd.DataFrame({'route':['Easy route','The hard','other route'],'grade':['9a+','6c','7b+']})
#原始等级
等级=['6b+'、'6c'、'6c+'、'7a'、'7b'、'7b+'、'7c'、'7c+'、'8a'、'8b'、'8b+'、'8c+'、'9a'、'9a+']
#定义函数
def转换(等级,等级):
返回等级。索引(等级)
#添加数字等级
df['grade_num']=[将df['grade']中的g转换为(g,grades)]
#开放数字
图,ax=plt.子批次()
#确保限制
ax.set_ylim([0,len(等级)])
ax.bar(x=df['route',height=df['grade_num'])
#确保限制
ax.set_ylim([0,len(等级)])
#设置滴答声
ax.set_yticks(列表(范围(等级)))
#设置勾号标签
ax.设置标签(等级)

也许
plt.bar(x=df.route,height=df.grade)
pd.DataFrame({'route':['Easy route', 'The hard', 'Another route'], 'grade':['9a+', '6c', '7b+']})