[英]How to move axis label to opposite side in Altair horizontal bar chart
My current chart looks like this:我当前的图表如下所示:
But I would like it to look like this with the percentages on the left side of the bar chart:但我希望它看起来像这样,条形图左侧的百分比是这样的:
What would be the easiest way to change this?改变这种情况的最简单方法是什么? Should I add more axis properties to my chart code?
我应该在图表代码中添加更多轴属性吗? This is the code I have so far for the visualization:
这是我迄今为止用于可视化的代码:
bars = alt.Chart(percentages_df).mark_bar().encode(
y=alt.Y('EMOJI',sort='-x'),
x=alt.X('PERCENT', axis=None)
)
text = bars.mark_text(
align='left',
# baseline='middle',
dx=3
).encode(
text=alt.Text('PERCENT_TEXT:N')
)
chart=(text+bars).configure_mark(
color='#DAC352'
).configure_scale(
bandPaddingInner = 0.1
).properties(
width = 450,
height = 180
).configure_view(
strokeWidth = 0
)
chart
I used the horizontal bar graph in the official reference as an example.我以官方参考中的水平条形图为例。 First I moved the y-axis to the left and set the label value there to the position of the overall y-axis.
首先,我将 y 轴向左移动,并将那里的标签值设置为整个 y 轴的位置。
import altair as alt
from vega_datasets import data
source = data.wheat()
bars = alt.Chart(source).mark_bar().encode(
x='wheat:Q',
y=alt.Y("year:O", axis=alt.Axis(ticks=False, domain=False, offset=25))
)
text = bars.mark_text(
align='right',
baseline='middle',
dx=3
).encode(
x=alt.value(-5),
text='wheat:Q'
)
(bars + text).properties(height=900)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.