[英]Specify plot title and facet title in Altair LayerChart
使用 iris 數據集,我們可以創建一個簡單的多面圖:
import altair as alt
from vega_datasets import data
iris = data.iris.url
alt.Chart(iris, title='Main Title').mark_bar().encode(
x='petalWidth:Q',
y='count(petalLength):Q',
color='species:N',
facet=alt.Facet('species:N', title=None)
)
在這里,我可以分別控制主要的 plot 標題和構面的標題。
現在假設我要創建相同的圖表,但為每個條添加文本注釋:
base = alt.Chart(iris).encode(
x='petalWidth:Q',
y='count(petalLength):Q',
color='species:N',
text='count(petalLength):Q'
)
c = base.mark_bar()
t = base.mark_text(dy=-6)
alt.layer(c, t).facet('species:N', title=None).properties(title='Main Title')
這一次,刻面上方有species
名稱。 在這種情況下,如何控制主要 plot 標題和構面標題?
gm_plot = alt.Chart(gm2018, width=200, height=150).mark_bar(opacity=0.7).encode(
alt.X('life_expectancy', bin=alt.Bin(maxbins=30)),
alt.Y('count()'),
alt.Color('region')).facet( facet=alt.Facet(
'region:N', title="test where the title in the facet arg goes", colums=1),
title={'text': ["can i pass a dict as in normal .properties()?",
" and get multilined titles"],
"subtitle" : ["multilined subtitles too?", "yes"]})
感謝您提出的問題及其滿足我需求的解決方案
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.