我正在尝试将许多统计数据的条形图可视化,并希望将 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)
等待解决,谢谢:)