3

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

1 Answers1

6

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

jakevdp
  • 77,104
  • 11
  • 125
  • 160
  • It is possible to add this footer without sacrificing the original title? I mean the following lines: ``` properties( title={ "text":["Movilidad en CDMX"], "subtitle": ["Jay Ballesteros (@jballesterosc_)", "Fuente: Elaboración propia con datos del COVID-19 Community Mobility Reports de Google. (Datos del 15 de febrero al 15 de noviembre de 2020"], } )``` – Jay Ballesteros C. Nov 19 '20 at 21:48
  • 4
    Sure, you can do this by wrapping your chart in a `concat`. For example: `alt.concat(my_chart_with_title).properties(title=...)` – jakevdp Nov 19 '20 at 22:00
  • 1
    @jakevdp - Since objects with "config" attribute cannot be used within ConcatChart, how can we configure both a title and a footnote? – blehman Sep 06 '22 at 22:03