简体   繁体   English

Altair:如何为轴添加一组固定的标签

[英]Altair: how to add a fixed set of labels for an axis

I've got a dataset that looks like so:我有一个看起来像这样的数据集:

    position    reputation
0   RW          5
1   ST          5
2   LW          5
3   GK          3
4   LW          4

What I've got now is a way of seeing how many players from each position have a particular reputation, letting the user select the minimum reputation with a slider:我现在得到的是一种查看每个 position 中有多少玩家具有特定声誉的方法,让用户 select 具有 slider 的最低声誉:

slider = pn.widgets.IntSlider(name='Integer Slider', start=1, end=5, step=1, value=3)

@pn.depends(slider.param.value)
def get_plot(min_rep):
     min_reputation = slider.value
     # create filter mask for the dataframe
     mask = (pbp['reputation'] >= min_reputation)
     tmp = pbp.loc[mask] # count of position
     # TODO: make this percent of each position, rather than count
     chart = alt.Chart(tmp).mark_bar().encode(
         x=alt.X('position'), 
         y='count(position)', 
         color=alt.Color('reputation:N')
     )
     return chart

The problem with this is that when the user selects a particular reputation, that also gets rid of any records that don't have a 'reputation' above the limit and thus we have different numbers of "positions" that we pull out of the dataset.这样做的问题是,当用户选择一个特定的声誉时,这也会删除任何没有超过限制的“声誉”的记录,因此我们有不同数量的“位置”我们从数据集中拉出. This is kind of visually jarring since the chart completely resizes and I've spent a long time trying to figure out how to have a fixed array of values for X and then count how many records are in each of those categories for Y. I've dug into transforms and filters but haven't had any luck yet.这在视觉上有点不和谐,因为图表完全调整了大小,我花了很长时间试图弄清楚如何为 X 设置一个固定的值数组,然后计算每个类别中有多少条记录用于 Y。我我已经研究了变换和过滤器,但还没有任何运气。 Altair/Vega is very data-driven so I may have to restructure my data into something that's like: Altair/Vega 非常受数据驱动,因此我可能不得不将我的数据重组为如下形式:

    position    reputation_5   reputation_4   reputation_3   reputation_2   reputation_1
0   RW          1              10             100            200            1000

I'd imagine there's a way to tell the Y axis to count each of the selected categories, but it'd be neat to find a way to do this in a more clever way.我想有一种方法可以告诉 Y 轴计算每个选定的类别,但是找到一种更聪明的方法来做到这一点会很巧妙。 Thanks for any pointers!感谢您的任何指点!

Try setting a constant width with .properties(width=200)尝试使用.properties(width=200)设置恒定宽度

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM