我正在尝试根据特定顺序对标准化堆积条形图进行排序。
我想要按此顺序排序的堆叠条:
Order = dict({'Paid work':1,'Education':2,'Sleep':3,'Other unpaid work':4,'Housework & Shopping':5,'Personal care':6, 'Eating and drinking':7,'TV and Radio':8,'Seeing friends':9,'Other leisures':10})
和国家/地区(Y 轴)也应按“带薪工作”条的长度排序。
但我得到的是图表左端带有“电视和广播”的订单,无法看到哪个国家/地区的人们花在“有偿工作”上的时间最多。
我的尝试:
错误代码:
alt.Chart(df).mark_bar(size=15).encode(
alt.Y('Country:O'),
alt.X('Time:Q', stack='normalize',sort=alt.EncodingSortField(field='Order',order='descending')),
alt.Color('Category:N',sort=alt.EncodingSortField(field='Order')),
tooltip=['Country', 'Category', 'Time']
).properties(
width=600,
height=600, title = {'text' :'How do people spend their time?',
'subtitle' : 'Average of minutes per day from time-use diaries for people between 15 and 64'})
我是这个平台的新手,请看一下本笔记本中的数据和我的简单代码:https://www.kaggle.com/hoangyennhi/exercise-dv https://www.kaggle.com/hoangyennhi/exercise-dv