mark_area 重置 Y 轴域 (Altair)
mark_area resetting the Y-axis domain (Altair)
我正在尝试使用 mark_area()
来显示时间序列的不确定性(如下所示)。但是,当我引入新层时,图表的Y轴域重置为默认值。
chart = alt.Chart(agg_data).encode(
x=alt.X(field='date', type='temporal', timeUnit='yearmonth', title='date'),
y=alt.Y(field=r'concentration', type='quantitative', title=r'[CH4] (ppb)',
scale=alt.Scale(domain=[1600, 1900])),
tooltip=[alt.Tooltip(field='date', type='temporal', title='date', format='%Y, %m'),
alt.Tooltip(field=r'concentration', type='nominal', title=r'concentration')]
).properties(width='container', height=300)
# Add uncertainty bands
bands = chart.mark_area(color='dodgerblue', fillOpacity=0.4).encode(
x=alt.X(field='date', type='temporal', timeUnit='yearmonth', title='date'),
y='lower bound:Q',
y2='upper bound:Q',
).properties(width='container', height=300)
l = chart.mark_line(color='dodgerblue')
p = chart.mark_point(color='dodgerblue', filled=True)
layer = alt.layer(bands, l, p)
这是我在添加 bands
:
之前得到的结果
及之后:
如何在使用 mark_area()
时保留图 1 中的 Y 轴域?
面积图默认包含零。要更改此设置,请在 y
编码中指定 alt.Scale(zero=False)
:
y=alt.Y('lower bound:Q', scale=alt.Scale(zero=False)),
我正在尝试使用 mark_area()
来显示时间序列的不确定性(如下所示)。但是,当我引入新层时,图表的Y轴域重置为默认值。
chart = alt.Chart(agg_data).encode(
x=alt.X(field='date', type='temporal', timeUnit='yearmonth', title='date'),
y=alt.Y(field=r'concentration', type='quantitative', title=r'[CH4] (ppb)',
scale=alt.Scale(domain=[1600, 1900])),
tooltip=[alt.Tooltip(field='date', type='temporal', title='date', format='%Y, %m'),
alt.Tooltip(field=r'concentration', type='nominal', title=r'concentration')]
).properties(width='container', height=300)
# Add uncertainty bands
bands = chart.mark_area(color='dodgerblue', fillOpacity=0.4).encode(
x=alt.X(field='date', type='temporal', timeUnit='yearmonth', title='date'),
y='lower bound:Q',
y2='upper bound:Q',
).properties(width='container', height=300)
l = chart.mark_line(color='dodgerblue')
p = chart.mark_point(color='dodgerblue', filled=True)
layer = alt.layer(bands, l, p)
这是我在添加 bands
:
及之后:
如何在使用 mark_area()
时保留图 1 中的 Y 轴域?
面积图默认包含零。要更改此设置,请在 y
编码中指定 alt.Scale(zero=False)
:
y=alt.Y('lower bound:Q', scale=alt.Scale(zero=False)),