Altair y轴限制自由

3
我正在尝试使用Altair Python可视化库,并成功使用facet函数。但是,在绘图中,所有分面都具有相同的y轴限制。我想知道是否可以实现类似于ggplot2的facet(~column,scales ="free")的功能。是否有办法在Altair中实现scales ==“free”?我查看了文档,并没有看到其他可以调整的变量。
我使用的代码如下:
alt.Chart(sum_tf).mark_line().encode(
    x='month:Q',
    y='value:Q',
).properties(
    width=600,
    height=100
).facet(
    facet='variable:O',
    columns=1
)
1个回答

5
你可以使用resolve_scale设置来控制复合图表中的比例尺是共享还是独立。默认情况下,比例尺是共享的:
alt.Chart(sum_tf).mark_line().encode(
    x='month:Q',
    y='value:Q',
).properties(
    width=600,
    height=100
).facet(
    facet='variable:O',
    columns=1
).resolve_scale(
    y='independent'
)

更多信息和示例请参见此处的文档:https://altair-viz.github.io/user_guide/scale_resolve.html


+1 太棒了,非常感谢。我之前不知道这个选项。我正在学习使用Altair,它是Python中最直观的可视化库。特别是在从R世界过来后,Altair真的帮了我很大忙。另外,有没有办法在PyCharm / Spyder中可视化Altair? - Jd Baba
1
https://altair-viz.github.io/user_guide/faq.html#does-altair-work-with-ipython-terminal-pycharm-spyder-my-favorite-ide - jakevdp

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接