[英]Change facet title position in Altair?
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',
)
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)
A general solution for this is to use the labelOrient
option of the header
parameter:对此的一般解决方案是使用
header
参数的labelOrient
选项:
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'))
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.