将 altair 条形图中的轴设置为整数
Set axis in altair bar chart as a integer
我正在尝试可视化许多统计数据的条形图,并想将 y 轴设置为整数(我的数据集中没有浮点型数据)
这是其中一张图表,我想更改坐标轴。
Image Link
这是我的 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
)
等待解决,谢谢:)
你可以设置tickMinStep=1
.
import altair as alt
import pandas as pd
source = pd.DataFrame({
'a': ['A', 'B', 'C', 'D'],
'b': [2.0, 1.0, 1.0, 3.0]
})
alt.Chart(source).mark_bar().encode(
alt.X('a:N'),
alt.Y('b:Q', axis=alt.Axis(tickMinStep=1))
)
我正在尝试可视化许多统计数据的条形图,并想将 y 轴设置为整数(我的数据集中没有浮点型数据)
这是其中一张图表,我想更改坐标轴。
Image Link
这是我的 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
)
等待解决,谢谢:)
你可以设置tickMinStep=1
.
import altair as alt
import pandas as pd
source = pd.DataFrame({
'a': ['A', 'B', 'C', 'D'],
'b': [2.0, 1.0, 1.0, 3.0]
})
alt.Chart(source).mark_bar().encode(
alt.X('a:N'),
alt.Y('b:Q', axis=alt.Axis(tickMinStep=1))
)