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


Python altair.Bin方法代码示例

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


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

示例1: violinplot

# 需要导入模块: import altair [as 别名]
# 或者: from altair import Bin [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: hist

# 需要导入模块: import altair [as 别名]
# 或者: from altair import Bin [as 别名]
def hist(self, bins=None, orientation="vertical", **kwargs):
        data = self._preprocess_data(with_index=False)
        column = data.columns[0]
        if isinstance(bins, int):
            bins = alt.Bin(maxbins=bins)
        elif bins is None:
            bins = True
        if orientation == "vertical":
            Indep, Dep = alt.X, alt.Y
        elif orientation == "horizontal":
            Indep, Dep = alt.Y, alt.X
        else:
            raise ValueError("orientation must be 'horizontal' or 'vertical'.")

        mark = self._get_mark_def({"type": "bar", "orient": orientation}, kwargs)
        return alt.Chart(data, mark=mark).encode(
            Indep(column, title=None, bin=bins), Dep("count()", title="Frequency")
        ) 
开发者ID:altair-viz,项目名称:altair_pandas,代码行数:20,代码来源:_core.py

示例3: test_df_hexbin

# 需要导入模块: import altair [as 别名]
# 或者: from altair import Bin [as 别名]
def test_df_hexbin():
    df = pd.DataFrame({"x": range(10), "y": range(10), "C": range(10)})
    gridsize = 10
    plot = df.vgplot.hexbin(x="x", y="y", gridsize=gridsize)
    assert plot.mark == "rect"
    utils.check_encodings(plot, x="x", y="y", color=utils.IGNORE)
    assert plot["encoding"]["x"]["bin"] == alt.Bin(maxbins=gridsize)
    assert plot["encoding"]["y"]["bin"] == alt.Bin(maxbins=gridsize)
    assert plot["encoding"]["color"]["aggregate"] == "count" 
开发者ID:altair-viz,项目名称:pdvega,代码行数:11,代码来源:test_core.py

示例4: test_df_hexbin_C

# 需要导入模块: import altair [as 别名]
# 或者: from altair import Bin [as 别名]
def test_df_hexbin_C():
    df = pd.DataFrame({"x": range(10), "y": range(10), "C": range(10)})
    gridsize = 10
    plot = df.vgplot.hexbin(x="x", y="y", C="C", gridsize=gridsize)
    assert plot.mark == "rect"
    utils.check_encodings(plot, x="x", y="y", color="C")
    assert plot["encoding"]["x"]["bin"] == alt.Bin(maxbins=gridsize)
    assert plot["encoding"]["y"]["bin"] == alt.Bin(maxbins=gridsize)
    assert plot["encoding"]["color"]["aggregate"] == "mean" 
开发者ID:altair-viz,项目名称:pdvega,代码行数:11,代码来源:test_core.py

示例5: show_document_length_distribution

# 需要导入模块: import altair [as 别名]
# 或者: from altair import Bin [as 别名]
def show_document_length_distribution(tokens: List[List[str]]):
    st.header("Document Length Distribution")
    document_lengths = get_document_lengths(tokens)
    doc_lengths = pd.DataFrame({"Token Count": document_lengths})
    doc_length_chart = (
        alt.Chart(doc_lengths, height=500, width=700)
        .mark_bar()
        .encode(
            alt.X("Token Count", bin=alt.Bin(maxbins=30)),
            alt.Y("count()", type="quantitative"),
        )
    )

    st.altair_chart(doc_length_chart) 
开发者ID:RTIInternational,项目名称:gobbli,代码行数:16,代码来源:explore.py

示例6: jointplot

# 需要导入模块: import altair [as 别名]
# 或者: from altair import Bin [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


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