当前位置: 首页>>代码示例>>Python>>正文


Python altair.condition方法代码示例

本文整理汇总了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 
开发者ID:retentioneering,项目名称:retentioneering-tools,代码行数:29,代码来源:plot.py

示例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 
开发者ID:altair-viz,项目名称:altair,代码行数:16,代码来源:test_core.py

示例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 
开发者ID:xoolive,项目名称:traffic,代码行数:38,代码来源:covid19_dataviz.py

示例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 
开发者ID:xoolive,项目名称:traffic,代码行数:36,代码来源:covid19_dataviz.py

示例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 
开发者ID:PythonCharmers,项目名称:starborn,代码行数:33,代码来源:core.py


注:本文中的altair.condition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。