如何减少 Altair 图形上的刻度数?

How do I reduce the number of ticks on an Altair graph?

我正在使用 Altair 创建图表,但由于某些奇怪的原因,它似乎为每个点生成了一个刻度。创建这样的图表 Altair Graph

如果我过滤数据框,它会产生奇怪的轴值。 Altair graph

有没有办法减少刻度数?我在 y 轴参数中尝试了 tickCount 但它不起作用,因为它似乎需要 integers.I 还尝试将轴值参数设置为列表 [0,0.2,0.4,0.6,0.8,1] 并且没有也工作。这是我的代码(抱歉太长了!)。提前致谢!

    a = alt.Chart(df_filtered).mark_point().encode(x =alt.X('Process_Time_(mins)', axis = alt.Axis(title='Process Time (mins)')),
    y = alt.Y('Heavy_Phase_%SS',axis=alt.Axis(title='Heavy Phase %SS', tickCount = 10),sort = 'descending'),
    color = alt.Color('DSP_Lot', legend = alt.Legend(title = 'DSP_Lot')),
    shape = alt.Shape('Strain', scale = alt.Scale(range = ["circle", "square", "cross", "diamond", "triangle-up", "triangle-down", "triangle-right", "triangle-left"])),
    tooltip = [alt.Tooltip('DSP_Lot',title  = 'Lot'), alt.Tooltip('Heavy_Phase_%SS', title = 'Heavy Phase %SS'),
    alt.Tooltip('Process_Time_(mins)', title = 'Process Time (mins)'), alt.Tooltip('Purpose', title = 'Purpose'), alt.Tooltip('Strain', title = 'Strain'),
    alt.Tooltip('Trial', title = 'Trial')]).properties(width = 1000, height = 500)

很难说没有 reproducible example 但我怀疑问题是您的 y 轴默认为标称编码类型,在这种情况下,每个唯一值都有一个刻度线。如果你在 Y 编码中指定一个数量类型,它可能会改善一些事情:

y = alt.Y('Heavy_Phase_%SS:Q', ...)

它默认为名义的原因可能是因为 pandas 数据框中的关联列具有字符串类型而不是数字类型。