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


Python altair.Axis方法代码示例

本文整理汇总了Python中altair.Axis方法的典型用法代码示例。如果您正苦于以下问题:Python altair.Axis方法的具体用法?Python altair.Axis怎么用?Python altair.Axis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在altair的用法示例。


在下文中一共展示了altair.Axis方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: violinplot

# 需要导入模块: import altair [as 别名]
# 或者: from altair import Axis [as 别名]
def violinplot(x=None, y=None, data=None, orient=None):
    # TODO: automatically infer orientation

    if orient is None or orient == 'v':
        kwargs = dict(
                    x=alt.X('count(*):Q',
                            axis=alt.Axis(grid=False, labels=False),
                            stack='center',
                            title=''),
                    y=alt.Y('{y}:Q'.format(y=y), bin=alt.Bin(maxbins=100)),
                    column='{x}:N'.format(x=x),
                    color='{x}:N'.format(x=x)
        )
    else:
        kwargs = dict(
                    y=alt.Y('count(*):Q',
                            axis=alt.Axis(grid=False, labels=False),
                            stack='center',
                            title=''),
                    x=alt.X('{x}:Q'.format(x=x), bin=alt.Bin(maxbins=100)),
                    row='{y}:N'.format(y=y),
                    color='{y}:N'.format(y=y)
        )
    chart = alt.Chart(data).mark_area().encode(**kwargs)
    return chart 
开发者ID:PythonCharmers,项目名称:starborn,代码行数:27,代码来源:core.py

示例2: jointplot

# 需要导入模块: import altair [as 别名]
# 或者: from altair import Axis [as 别名]
def jointplot(x, y, data, kind='scatter', hue=None, xlim=None, ylim=None):
    if xlim is None:
        xlim = get_limit_tuple(data[x])
    if ylim is None:
        ylim = get_limit_tuple(data[y])
    xscale = alt.Scale(domain=xlim)
    yscale = alt.Scale(domain=ylim)
 
    points = scatterplot(x, y, data, hue=hue, xlim=xlim, ylim=ylim)

    area_args = {'opacity': .3, 'interpolate': 'step'}

    blank_axis = alt.Axis(title='')

    top_hist = alt.Chart(data).mark_area(**area_args).encode(
        alt.X('{x}:Q'.format(x=x),
              # when using bins, the axis scale is set through
              # the bin extent, so we do not specify the scale here
              # (which would be ignored anyway)
              bin=alt.Bin(maxbins=20, extent=xscale.domain),
              stack=None,
              axis=blank_axis,
             ),
        alt.Y('count()', stack=None, axis=blank_axis),
        alt.Color('{hue}:N'.format(hue=hue)),
    ).properties(height=60)

    right_hist = alt.Chart(data).mark_area(**area_args).encode(
        alt.Y('{y}:Q'.format(y=y),
              bin=alt.Bin(maxbins=20, extent=yscale.domain),
              stack=None,
              axis=blank_axis,
             ),
        alt.X('count()', stack=None, axis=blank_axis),
        alt.Color('{hue}:N'.format(hue=hue)),
    ).properties(width=60)

    return top_hist & (points | right_hist) 
开发者ID:PythonCharmers,项目名称:starborn,代码行数:40,代码来源:core.py

示例3: boxplot_vertical

# 需要导入模块: import altair [as 别名]
# 或者: from altair import Axis [as 别名]
def boxplot_vertical(x=None, y=None, hue=None, data=None, order=None):

    # orientation_mapper = {'v': {'x': 'x', 'y': 'y'},
    #                       'h': {'x': 'y', 'y': 'x'}}

    # Define aggregate fields
    lower_box = 'q1({value}):Q'.format(value=y)
    lower_whisker = 'min({value}):Q'.format(value=y)
    upper_box = 'q3({value}):Q'.format(value=y)
    upper_whisker = 'max({value}):Q'.format(value=y)
    
    kwargs = {'x': '{x}:O'.format(x=x)}

    if hue is not None:
        kwargs['color'] = '{hue}:N'.format(hue=hue)
        # Swap x for column
        column, kwargs['x'] = kwargs['x'], '{hue}:N'.format(hue=hue)

    base = alt.Chart().encode(
        **kwargs
    )

    # Compose each layer individually
    lower_whisker = base.mark_rule().encode(
        y=alt.Y(lower_whisker, axis=alt.Axis(title=y)),
        y2=lower_box,
    )
    
    middle_bar_kwargs = dict(
        y=lower_box,
        y2=upper_box,
    )
    if hue is None:
        middle_bar_kwargs['color'] = 'year:O'

    middle_bar = base.mark_bar(size=10.0).encode(**middle_bar_kwargs)

    upper_whisker = base.mark_rule().encode(
        y=upper_whisker,
        y2=upper_box,
    )
    
    middle_tick = base.mark_tick(
        color='white',
        size=10.0
    ).encode(
        y='median({value}):Q'.format(value=y),
    )
    
    chart = (lower_whisker + upper_whisker + middle_bar + middle_tick)

    if hue is None:
        chart.data = data
        return chart
    else:
        return chart.facet(column=column, data=data) 
开发者ID:PythonCharmers,项目名称:starborn,代码行数:58,代码来源:core.py


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