考虑以下小示例(基于此图库示例):
import altair as alt
from vega_datasets import data
import polars as pl
# add a column indicating the year associated with each date
source = pl.from_pandas(data.stocks()).with_columns(year=pl.col.date.dt.year())
# an MSFT specific plot
msft_plot = (
alt.Chart(source.filter(pl.col.symbol.eq("MSFT")))
.mark_line()
.encode(x="date:T", y="price:Q", color="year:O")
)
# the original plot: https://altair-viz.github.io/gallery/line_chart_with_points.html
all_plot = (
alt.Chart(source)
.mark_line()
.encode(x="date:T", y="price:Q", color="symbol:N")
)
msft_plot & all_plot
这将产生以下输出:
另一方面,如果我仅绘制all_plot
:
当我连接时,如何阻止图例合并msft_plot & all_plot
?
您可以使用
(msft_plot & all_plot).resolve_scale(color='independent')
:resolve_
您可以在本文档的这一部分找到有关这些方法的更多信息。