Python 中的 Altair 图表:如何删除 'HConcatChart' 的复合图表边框

Altair Chart in Python: how to remove the counpound chart border for the 'HConcatChart'

import altair as alt
from vega_datasets import data

iris = data.iris.url

chart1 = alt.Chart(iris).mark_point().encode(
    x='petalLength:Q',
    y='petalWidth:Q',
    color='species:N'
).properties(
    height=300,
    width=300
)

chart2 = alt.Chart(iris).mark_bar().encode(
    x='count()',
    y=alt.Y('petalWidth:Q', bin=alt.Bin(maxbins=30)),
    color='species:N'
).properties(
    height=300,
    width=100
)

alt.hconcat(chart1, chart2).ViewConfig(strokeWidth = 0)

请问有什么方法可以让这两个横图的边框不显示吗? .config_view 不适用于复合图表。

谢谢。

您可以在连接图表上使用.configure_view()方法来移除每个子图表中的视图边框:


import altair as alt
from vega_datasets import data

iris = data.iris.url

chart1 = alt.Chart(iris).mark_point().encode(
    x='petalLength:Q',
    y='petalWidth:Q',
    color='species:N'
).properties(
    height=300,
    width=300
)

chart2 = alt.Chart(iris).mark_bar().encode(
    x='count()',
    y=alt.Y('petalWidth:Q', bin=alt.Bin(maxbins=30)),
    color='species:N'
).properties(
    height=300,
    width=100
)

alt.hconcat(chart1, chart2).configure_view(strokeWidth = 0)