如何删除 Y 轴上的刻度但在 Altair 图表中保留标签

How to remove ticks on Y-axis but maintain labels in Altair chart

我的图表是这样的:

但我希望它几乎完全匹配此图表:

如何删除 Y 轴上的刻度但保留百分比标签?另外,有没有办法像原始图像那样在百分比标签和条形开始之间创建更多 space?

这是我正在使用的代码:

chart = alt.Chart(percentages_df).mark_bar(size=17, color= '#e6ab02').encode(
    # encode x as the percent, and hide the axis
    x=alt.X(
        'PERCENT',axis=None),
    y=alt.Y(
        'PERCENT_TEXT',
         axis=alt.Axis(tickCount=5,title='') ,sort='-y'))

text = alt.Chart(percentages_df).mark_text().encode(
    y=alt.Y('PERCENT_TEXT',axis=None, sort='-y'),
    text='EMOJI'
)
new_chart = alt.hconcat(text, chart).configure_view(strokeWidth=0).configure_axis(grid=False)
new_chart

您可以使用 tickSize 轴 属性 执行此操作;例如:

import altair as alt
import pandas as pd

source = pd.DataFrame({
    'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],
    'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]
})

alt.Chart(source).mark_bar().encode(
    x = 'b',
    y=alt.Y('a', axis=alt.Axis(tickSize=0))
)