简体   繁体   English

在 X 轴上翻转垂直条形图 Altair

[英]Flip vertical bar plot over X axis Altair

If I have this bar plot:如果我有这个条形图:

在此处输入图片说明

How can I flip it like this我怎么能像这样翻转它

在此处输入图片说明

Of course preserving right labels.当然保留正确的标签。

You can do this by swapping the x and y encodings and adjusting the axis properties accordingly.您可以通过交换xy编码并相应地调整轴属性来做到这一点。 For example, if you have this chart:例如,如果您有此图表:

import altair as alt
import pandas as pd
import numpy as np

np.random.seed(1701)
df = pd.DataFrame({
    'data': 6 + np.random.randn(500)
})

alt.Chart(df).mark_bar().encode(
    x=alt.X('data', bin=alt.Bin(maxbins=40)),
    y='count()'
).properties(width=800, height=150)

在此处输入图片说明

You can create a rotated version like this:您可以像这样创建旋转版本:

alt.Chart(df).mark_bar().encode(
    y=alt.Y('data', bin=alt.Bin(maxbins=40), axis=alt.Axis(orient='right')),
    x=alt.X('count()', scale=alt.Scale(reverse=True))
).properties(width=150, height=800)

在此处输入图片说明

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

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