Altair: Subtitle Documentation and styling

Created on 17 Jan 2020  路  6Comments  路  Source: altair-viz/altair

At last! There are subtitles in for altair charts(via a vega-lite update)! How splendid! This issue identifies a documentation bug and maybe a styling bug revolving around this newly birthed feature:

  • I don't believe that there is any documentation of the mechanism for adding subtitles (or multiline titles) to charts! It's a great feature it should be easy to find!

  • The title configuration section of the documentation appears to suggest that there should be various subtitle styling operators (subtitleColor, subtitleFont, subtitleFontSize, subtitleFontStyle, subtitleFontWeight, subtitleLineHeight, subtitlePadding specifically), but all of the variations that i've tried on them appear not to work? For instance the following should ostensibly produce a chart with a red subtitle

import altair as alt
from vega_datasets import data

chart = alt.Chart(data.cars.url).mark_point().encode(
    x='Horsepower:Q',
    y='Miles_per_Gallon:Q',
).properties(
    title={
      "text": ["First line of title", "Second line of title"], 
      "subtitle": ["Cool first line of subtitle", "Even cooler second line wow dang"]
    }
)

chart.configure_title(
    fontSize=20,
    font='Courier',
    anchor='start',
    color='gray',
   subtitleColor='red'
)

Unfortunately it produces a chart with an unstyled subtitle:

Screen Shot 2020-01-17 at 12 40 43 AM

I totally admit that i might be misreading this, but, if not, it seems like a bug. I'm happy to help contribute documentation once a solution is known

bug vega-lite-related

Most helpful comment

Apparently it is both a documentation bug and a regular bug, after a helpful hint from @domoritz on the upstream issue, I was able to get the styling applied to the subtitle like so:

import altair as alt
from vega_datasets import data

chart = alt.Chart(data.cars.url).mark_point().encode(
    x='Horsepower:Q',
    y='Miles_per_Gallon:Q',
).properties(
    title={
      "text": ["First line of title", "Second line of title"], 
      "subtitle": ["Cool first line of subtitle", "Even cooler second line wow dang"],
      "color": "red",
      "subtitleColor": "green"
    }
)
chart

All 6 comments

It looks like a bug that should be reported upstream to Vega-Lite

Reported to upstream!

Apparently it is both a documentation bug and a regular bug, after a helpful hint from @domoritz on the upstream issue, I was able to get the styling applied to the subtitle like so:

import altair as alt
from vega_datasets import data

chart = alt.Chart(data.cars.url).mark_point().encode(
    x='Horsepower:Q',
    y='Miles_per_Gallon:Q',
).properties(
    title={
      "text": ["First line of title", "Second line of title"], 
      "subtitle": ["Cool first line of subtitle", "Even cooler second line wow dang"],
      "color": "red",
      "subtitleColor": "green"
    }
)
chart

@jakevdp, I'm interested in the idea of adding examples to the gallery that tackle basic customizations like adding a subtitle. Would you be open to a new section there that showed how to do something like this? It seems like it would pretty tough for a newbie to figure out.

Sure, that would be great

I think a narrative documentation section would be better than more gallery examples. The gallery is already pretty crowded, and it's not always easy to find the relevant chart.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fischcheng picture fischcheng  路  4Comments

SuperShinyEyes picture SuperShinyEyes  路  3Comments

nielsmde picture nielsmde  路  4Comments

tonylee3399 picture tonylee3399  路  3Comments

galloramiro picture galloramiro  路  3Comments