How can I move the facet titles (in this case, year) to be above each plot? The default seems to be on the side of the chart. Can this be easily changed?
import altair as alt
from vega_datasets import data
df = data.seattle_weather()
alt.Chart(df).mark_rect().encode(
alt.Y('month(date):O', title='day'),
alt.X('date(date):O', title='month'),
color='temp_max:Q'
).facet(
row='year(date):N',
)
A general solution for this is to use the labelOrient
option of the header
parameter:
df = df[df.date.dt.year < 2014] # make a smaller chart
alt.Chart(df).mark_rect().encode(
alt.Y('month(date):O', title='day'),
alt.X('date(date):O', title='month'),
color='temp_max:Q'
).facet(
row=alt.Row('year(date):N', header=alt.Header(labelOrient='top'))
)
One solution is to remove the row specification and set the facet to have a single column
import altair as alt
from vega_datasets import data
df = data.seattle_weather()
alt.Chart(df).mark_rect().encode(
alt.Y('month(date):O', title='day'),
alt.X('date(date):O', title='month'),
color='temp_max:Q'
).facet('year(date):N', columns=1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With