如何更改Altair箱图信息框以显示平均值而不是中位数?

时间:2019-12-05 11:31:11

标签: python pandas altair

我已经使用Python中的Altair库创建了一些数据的可视化。当前,悬停信息框显示中位数。如何更改聚合以显示均值?

1 个答案:

答案 0 :(得分:2)

如果像https://altair-viz.github.io/gallery/boxplot.html中的示例那样谈论标准箱线图,则没有简单的方法将中位数更改为均值。这是因为中位数在基于其的vega-lite boxplot宏中进行了硬编码:https://vega.github.io/vega-lite/docs/boxplot.html

如果需要更大的灵活性,可以手动构造图表组件,并使用平均值而不是中位数;例如:

<ui:include src="/WEB-INF/includes/head.xhtml">
    <ui:param name="description" value="Overridden description" />
</ui:include>

enter image description here