Jay Ballesteros C.
Jay Ballesteros C.

Reputation: 303

How to add a Text Footer to an Altair graph?

It is possible to add a footer to an Altair graph?

I've been looking for options but I only found the textand subtitle title properties().

Here's my plot code (from a concatenated graph)

mobility_colima.configure_axis(
    labelFontSize=7,
    titleFontSize=7
).properties(
    title={
        "text":["Movilidad en CDMX"],
        "subtitle": ["Jay Ballesteros (@jballesterosc_)"],
    }
)

Here's the output where I'll like to add a footer:

enter image description here

Upvotes: 3

Views: 1510

Answers (1)

jakevdp
jakevdp

Reputation: 86533

There is no footer property for Altair charts, but you can abuse the title property to add a footer. It might look something like this:

import altair as alt
import numpy as np
import pandas as pd

x = np.arange(100)
source = pd.DataFrame({
  'x': x,
  'f(x)': np.sin(x / 5)
})

alt.Chart(source).mark_line().encode(
    x='x',
    y='f(x)'
).properties(
    title=alt.TitleParams(
        ['This is a fake footer.', 'If you want multiple lines,', 'you can put them in a list.'],
        baseline='bottom',
        orient='bottom',
        anchor='end',
        fontWeight='normal',
        fontSize=10
    )
)

enter image description here

Upvotes: 6

Related Questions