我可以将 altair 轴标题转换为链接吗?
Can I turn altair axis titles into links?
在 altair 中,可以将轴标题转换为链接吗?
(我知道如何使用 href 作为点,但不确定我是否可以对轴标签做类似的事情。)
我认为不可能像那样格式化轴标题,并且在 the Vega-Lite docs 中没有看到任何建议您可以的 属性。但是,您可以策略性地放置文本标记以获得相同的结果:
import altair as alt
from vega_datasets import data
cars = data.cars()
chart = alt.Chart(cars).mark_circle().encode(
x=alt.X('Miles_per_Gallon', title=''),
y='Weight_in_lbs',
color='Origin'
)
text = alt.Chart().mark_text(
align="center",
baseline="top",
fontSize=11,
fontWeight=600,
color='#007bff',
href='https://whosebug.com'
).encode(
x=alt.value(200), # pixels from left
y=alt.value(322), # pixels from top
text=alt.value("Miles_per_Gallon")
)
text + chart
在 altair 中,可以将轴标题转换为链接吗?
(我知道如何使用 href 作为点,但不确定我是否可以对轴标签做类似的事情。)
我认为不可能像那样格式化轴标题,并且在 the Vega-Lite docs 中没有看到任何建议您可以的 属性。但是,您可以策略性地放置文本标记以获得相同的结果:
import altair as alt
from vega_datasets import data
cars = data.cars()
chart = alt.Chart(cars).mark_circle().encode(
x=alt.X('Miles_per_Gallon', title=''),
y='Weight_in_lbs',
color='Origin'
)
text = alt.Chart().mark_text(
align="center",
baseline="top",
fontSize=11,
fontWeight=600,
color='#007bff',
href='https://whosebug.com'
).encode(
x=alt.value(200), # pixels from left
y=alt.value(322), # pixels from top
text=alt.value("Miles_per_Gallon")
)
text + chart