If I have this bar plot:
How can I flip it like this
Of course preserving right labels.
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. 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)