Altair 将对数线性回归添加到带有选择的图表中
Altair add log linear regression to chart with selection
我有一个 Altair 散点图,绘制了日期与数量。
该图表包括一个选择菜单,用于突出显示来自不同域的点。
我想在其上添加逻辑回归,transform_regression
。
但是我在执行时遇到错误。
这是我的代码:
import altair as alt
alt.themes.enable('fivethirtyeight')
selection = alt.selection_multi(fields=['Domain'], bind='legend')
chart = alt.Chart(df, width=1100, height=600,
title="Parameter count of ML systems through time")\
.mark_point(size=120, filled=False).encode(
x=alt.X('Publication date:T'),
y=alt.Y('Parameters:Q',scale=alt.Scale(type='log'), axis=alt.Axis(format=".1e")),
color='Domain',
shape = 'Domain',
tooltip=['System',
'Reference',
'Publication date',
alt.Tooltip('Parameters', format=".1e"),
'Domain'],
opacity=alt.condition(selection, alt.value(1), alt.value(0.2))
).add_selection(
selection
)
regression = chart.transform_regression(
on="Publication date", regression="Parameters", groupby=["Domain"]
).mark_line()
alt.layer(chart, regression).configure_axis(labelFontSize=20,titleFontSize=30).configure_legend(
titleFontSize=20,
labelFontSize =18,
gradientLength=400,
gradientThickness=30,
symbolSize = 130
)
这是我得到的错误:Javascript Error: Duplicate signal name: "selector027_tuple" This usually means there's a typo in your chart specification. See the javascript console for the full traceback.
我无法理解 javascript 控制台的输出,但它显示如下:
Uncaught (in promise) Javascript Error: Duplicate signal name: "selector028_tuple"<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.
Promise.catch (async)
displayChart @ VM1182:32
(anonymous) @ VM1182:45
load (async)
(anonymous) @ VM1182:19
loadScript @ VM1182:15
(anonymous) @ VM1182:43
由于回归图是基于已添加选择的点图,因此在对这两个图表进行分层时,您将添加两次。相反,创建没有选择的点图表并将其仅添加到图层中的一个图表:
alt.layer(chart.add_selection(selection), regression)
或一次到分层图表:
alt.layer(chart, regression).add_selection(selection)
我有一个 Altair 散点图,绘制了日期与数量。 该图表包括一个选择菜单,用于突出显示来自不同域的点。
我想在其上添加逻辑回归,transform_regression
。
但是我在执行时遇到错误。
这是我的代码:
import altair as alt
alt.themes.enable('fivethirtyeight')
selection = alt.selection_multi(fields=['Domain'], bind='legend')
chart = alt.Chart(df, width=1100, height=600,
title="Parameter count of ML systems through time")\
.mark_point(size=120, filled=False).encode(
x=alt.X('Publication date:T'),
y=alt.Y('Parameters:Q',scale=alt.Scale(type='log'), axis=alt.Axis(format=".1e")),
color='Domain',
shape = 'Domain',
tooltip=['System',
'Reference',
'Publication date',
alt.Tooltip('Parameters', format=".1e"),
'Domain'],
opacity=alt.condition(selection, alt.value(1), alt.value(0.2))
).add_selection(
selection
)
regression = chart.transform_regression(
on="Publication date", regression="Parameters", groupby=["Domain"]
).mark_line()
alt.layer(chart, regression).configure_axis(labelFontSize=20,titleFontSize=30).configure_legend(
titleFontSize=20,
labelFontSize =18,
gradientLength=400,
gradientThickness=30,
symbolSize = 130
)
这是我得到的错误:Javascript Error: Duplicate signal name: "selector027_tuple" This usually means there's a typo in your chart specification. See the javascript console for the full traceback.
我无法理解 javascript 控制台的输出,但它显示如下:
Uncaught (in promise) Javascript Error: Duplicate signal name: "selector028_tuple"<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.
Promise.catch (async)
displayChart @ VM1182:32
(anonymous) @ VM1182:45
load (async)
(anonymous) @ VM1182:19
loadScript @ VM1182:15
(anonymous) @ VM1182:43
由于回归图是基于已添加选择的点图,因此在对这两个图表进行分层时,您将添加两次。相反,创建没有选择的点图表并将其仅添加到图层中的一个图表:
alt.layer(chart.add_selection(selection), regression)
或一次到分层图表:
alt.layer(chart, regression).add_selection(selection)