小编M.F*_*qqi的帖子

将 altair 条形图中的轴设置为整数

我正在尝试将许多统计数据的条形图可视化,并希望将 y 轴设置为整数(我的数据集中没有浮点型数据)

这是我想更改轴的图表之一。

图片链接

这是我的python源代码来可视化这个图表

def plot_3(data,x,y,width):
    selector = alt.selection_single(encodings=['x', 'color'])
    bars = alt.Chart(data).mark_bar(opacity=0.8).encode(
        alt.X('Tahun:O', title=''),
        alt.Y('N:Q', title=x, axis=alt.Axis(format='.0f')), # this format axis has no effect
        alt.Column('Keterangan:N', title=y),color=alt.condition(selector, 'Tahun:O', alt.value('lightgray')),
        tooltip = ['Tahun','Keterangan','N','Satuan']
    ).add_selection(selector
    ).interactive(
    ).resolve_scale(x='independent')
    
    return bars.properties(width=width
    )
Run Code Online (Sandbox Code Playgroud)

等待解决,谢谢:)

python axis altair

4
推荐指数
1
解决办法
762
查看次数

标签 统计

altair ×1

axis ×1

python ×1