本文整理汇总了Python中altair.condition方法的典型用法代码示例。如果您正苦于以下问题:Python altair.condition方法的具体用法?Python altair.condition怎么用?Python altair.condition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类altair
的用法示例。
在下文中一共展示了altair.condition方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: altair_step_matrix
# 需要导入模块: import altair [as 别名]
# 或者: from altair import condition [as 别名]
def altair_step_matrix(diff, plot_name=None, title='', vmin=None, vmax=None, font_size=12, **kwargs):
heatmap_data = diff.reset_index().melt('index')
heatmap_data.columns = ['y', 'x', 'z']
table = alt.Chart(heatmap_data).encode(
x=alt.X('x:O', sort=None),
y=alt.Y('y:O', sort=None)
)
heatmap = table.mark_rect().encode(
color=alt.Color(
'z:Q',
scale=alt.Scale(scheme='blues'),
)
)
text = table.mark_text(
align='center', fontSize=font_size
).encode(
text='z',
color=alt.condition(
abs(alt.datum.z) < 0.8,
alt.value('black'),
alt.value('white'))
)
heatmap_object = (heatmap + text).properties(
width=3 * font_size * len(diff.columns),
height=2 * font_size * diff.shape[0]
)
return heatmap_object, plot_name, None, diff.retention.retention_config
示例2: test_infer_encoding_types_with_condition
# 需要导入模块: import altair [as 别名]
# 或者: from altair import condition [as 别名]
def test_infer_encoding_types_with_condition(channels):
args, kwds = _getargs(
x=alt.condition("pred1", alt.value(1), alt.value(2)),
y=alt.condition("pred2", alt.value(1), "yval"),
strokeWidth=alt.condition("pred3", "sval", alt.value(2)),
)
expected = dict(
x=channels.XValue(2, condition=channels.XValue(1, test="pred1")),
y=channels.Y("yval", condition=channels.YValue(1, test="pred2")),
strokeWidth=channels.StrokeWidthValue(
2, condition=channels.StrokeWidth("sval", test="pred3")
),
)
assert infer_encoding_types(args, kwds, channels) == expected
示例3: airline_chart
# 需要导入模块: import altair [as 别名]
# 或者: from altair import condition [as 别名]
def airline_chart(
source: alt.Chart, subset: List[str], name: str, loess=True
) -> alt.Chart:
chart = source.transform_filter(
alt.FieldOneOfPredicate(field="airline", oneOf=subset)
)
highlight = alt.selection(
type="single", nearest=True, on="mouseover", fields=["airline"]
)
points = (
chart.mark_point()
.encode(
x="day",
y=alt.Y("rate", title="# of flights (normalized)"),
color=alt.Color("airline", legend=alt.Legend(title=name)),
tooltip=["day", "airline", "count"],
opacity=alt.value(0.3),
)
.add_selection(highlight)
)
lines = chart.mark_line().encode(
x="day",
y="rate",
color="airline",
size=alt.condition(~highlight, alt.value(1), alt.value(3)),
)
if loess:
lines = lines.transform_loess(
"day", "rate", groupby=["airline"], bandwidth=0.2
)
return lines + points
示例4: airport_chart
# 需要导入模块: import altair [as 别名]
# 或者: from altair import condition [as 别名]
def airport_chart(source: alt.Chart, subset: List[str], name: str) -> alt.Chart:
chart = source.transform_filter(
alt.FieldOneOfPredicate(field="airport", oneOf=subset)
)
highlight = alt.selection(
type="single", nearest=True, on="mouseover", fields=["airport"]
)
points = (
chart.mark_point()
.encode(
x="day",
y=alt.Y("count", title="# of departing flights"),
color=alt.Color("airport", legend=alt.Legend(title=name)),
tooltip=["day", "airport", "city", "count"],
opacity=alt.value(0.3),
)
.add_selection(highlight)
)
lines = (
chart.mark_line()
.encode(
x="day",
y="count",
color="airport",
size=alt.condition(~highlight, alt.value(1), alt.value(3)),
)
.transform_loess("day", "count", groupby=["airport"], bandwidth=0.2)
)
return lines + points
示例5: heatmap
# 需要导入模块: import altair [as 别名]
# 或者: from altair import condition [as 别名]
def heatmap(data, vmin=None, vmax=None, annot=None, fmt='.2g'):
# We always want to have a DataFrame with semantic information
if not isinstance(data, pd.DataFrame):
matrix = np.asarray(data)
data = pd.DataFrame(matrix)
melted = data.stack().reset_index(name='Value')
x = data.columns.name
y = data.index.name
heatmap = alt.Chart(melted).mark_rect().encode(
alt.X('{x}:O'.format(x=x), scale=alt.Scale(paddingInner=0)),
alt.Y('{y}:O'.format(y=y), scale=alt.Scale(paddingInner=0)),
color='Value:Q'
)
if not annot:
return heatmap
# Overlay text
text = alt.Chart(melted).mark_text(baseline='middle').encode(
x='{x}:O'.format(x=x),
y='{y}:O'.format(y=y),
text=alt.Text('Value', format=fmt),
color=alt.condition(alt.expr.datum['Value'] > 70,
alt.value('black'),
alt.value('white'))
)
return heatmap + text