Search code examples
pythonpython-3.xstreamlitaltair

Repeated values in date axis


I'm trying to make a bar graph which has its X axis's type as time. I formatted it using 'utcyearmonth', but the X axis's label repeats values.

Any ideas on what I'm doing wrong?

This is what happens to the graph

The code I have written is:

serie_temporal = alt.Chart(base_filtrada).mark_bar(size=60).encode(
    x=alt.X(
        'utcyearmonth(Data):T', 
        axis=alt.Axis(format="%Y %B"),
        scale = alt.Scale(nice={'interval': 'month', 'step': 1})
    ),
    y='sum(Valor):Q',
    color='Tipo de despesa'
).properties(
    height=400
)

I already tried changing the axis type from time to nominal, ordinal and quantitative and removing the scale configuration.


Solution

  • Instead, use:

    x = alt.X("date:O", timeUnit="yearmonth")
    

    Source: https://github.com/altair-viz/altair/issues/2876