Reputation: 101
I am trying to visualization a bar plot of many statistic data, and wanna set y-axis as a integer (there is no float type data in my dataset)
This is one of the charts, which I want to change the axis.
This is my python source code to visualization this chart
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
)
waiting for the solution, thank you :)
Upvotes: 6
Views: 3031
Reputation: 1344
You could set 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))
)
Upvotes: 9