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


Python altair.X属性代码示例

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


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

示例1: visualize

# 需要导入模块: import altair [as 别名]
# 或者: from altair import X [as 别名]
def visualize(display_df):
        viridis = ['#440154', '#472c7a', '#3b518b', '#2c718e', '#21908d', '#27ad81', '#5cc863', '#aadc32', '#fde725']
        import altair as alt
        color_scale = alt.Scale(
            domain=(display_df.dropna().trending.min(),
                    0,
                    display_df.dropna().trending.max()),
            range=[viridis[0], viridis[len(viridis) // 2], viridis[-1]]
        )

        return alt.Chart(display_df).mark_circle().encode(
            alt.X('variable'),
            alt.Y('term'),
            size='frequency',
            color=alt.Color('trending:Q', scale=color_scale),
        ) 
开发者ID:JasonKessler,项目名称:scattertext,代码行数:18,代码来源:BubbleDiachronicVisualization.py

示例2: scatterplot

# 需要导入模块: import altair [as 别名]
# 或者: from altair import X [as 别名]
def scatterplot(x, y, data, hue=None, xlim=None, ylim=None):
    # TODO: refactor so it uses category_chart_kwargs?
    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)
    
    other_args = {'color': '{hue}:N'.format(hue=hue)} if hue else {}
    points = alt.Chart(data).mark_circle().encode(
        alt.X(x, scale=xscale),
        alt.Y(y, scale=yscale),
        **other_args
    )
    return points 
开发者ID:PythonCharmers,项目名称:starborn,代码行数:18,代码来源:core.py

示例3: pairplot

# 需要导入模块: import altair [as 别名]
# 或者: from altair import X [as 别名]
def pairplot(data, hue=None, vars=None):
    if vars is None:
        vars = list(data.columns)

    chart = alt.Chart(data).mark_circle().encode(
                alt.X(alt.repeat("column"), type='quantitative'),
                alt.Y(alt.repeat("row"), type='quantitative'),
                color='{hue}:N'.format(hue=hue)
            ).properties(
                width=250,
                height=250
            ).repeat(
                row=vars,
                column=vars
            )
    return chart 
开发者ID:PythonCharmers,项目名称:starborn,代码行数:18,代码来源:core.py

示例4: violinplot

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

示例5: hist

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

示例6: _x

# 需要导入模块: import altair [as 别名]
# 或者: from altair import X [as 别名]
def _x(x, df, ordinal_threshold=6, **kwargs):
    return alt.X(
        field=x,
        type=infer_vegalite_type(df[x], ordinal_threshold=ordinal_threshold),
        **kwargs
    ) 
开发者ID:altair-viz,项目名称:pdvega,代码行数:8,代码来源:_core.py

示例7: frame_selector_ui

# 需要导入模块: import altair [as 别名]
# 或者: from altair import X [as 别名]
def frame_selector_ui(summary):
    st.sidebar.markdown("# Frame")

    # The user can pick which type of object to search for.
    object_type = st.sidebar.selectbox("Search for which objects?", summary.columns, 2)

    # The user can select a range for how many of the selected objecgt should be present.
    min_elts, max_elts = st.sidebar.slider("How many %ss (select a range)?" % object_type, 0, 25, [10, 20])
    selected_frames = get_selected_frames(summary, object_type, min_elts, max_elts)
    if len(selected_frames) < 1:
        return None, None

    # Choose a frame out of the selected frames.
    selected_frame_index = st.sidebar.slider("Choose a frame (index)", 0, len(selected_frames) - 1, 0)

    # Draw an altair chart in the sidebar with information on the frame.
    objects_per_frame = summary.loc[selected_frames, object_type].reset_index(drop=True).reset_index()
    chart = alt.Chart(objects_per_frame, height=120).mark_area().encode(
        alt.X("index:Q", scale=alt.Scale(nice=False)),
        alt.Y("%s:Q" % object_type))
    selected_frame_df = pd.DataFrame({"selected_frame": [selected_frame_index]})
    vline = alt.Chart(selected_frame_df).mark_rule(color="red").encode(
        alt.X("selected_frame:Q", axis=None)
    )
    st.sidebar.altair_chart(alt.layer(chart, vline))

    selected_frame = selected_frames[selected_frame_index]
    return selected_frame_index, selected_frame

# Select frames based on the selection in the sidebar 
开发者ID:streamlit,项目名称:demo-self-driving,代码行数:32,代码来源:app.py

示例8: altair_step_matrix

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

示例9: show_document_length_distribution

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

示例10: st_heatmap

# 需要导入模块: import altair [as 别名]
# 或者: from altair import X [as 别名]
def st_heatmap(
    heatmap_df: pd.DataFrame, x_col_name: str, y_col_name: str, color_col_name: str
):
    heatmap = (
        alt.Chart(heatmap_df, height=700, width=700)
        .mark_rect()
        .encode(alt.X(x_col_name), alt.Y(y_col_name), alt.Color(color_col_name))
    )
    st.altair_chart(heatmap) 
开发者ID:RTIInternational,项目名称:gobbli,代码行数:11,代码来源:explore.py

示例11: jointplot

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

示例12: heatmap

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

示例13: _xy

# 需要导入模块: import altair [as 别名]
# 或者: from altair import X [as 别名]
def _xy(self, mark, **kwargs):
        data = self._preprocess_data(with_index=True)
        return (
            alt.Chart(data, mark=self._get_mark_def(mark, kwargs))
            .encode(
                x=alt.X(data.columns[0], title=None),
                y=alt.Y(data.columns[1], title=None),
                tooltip=list(data.columns),
            )
            .interactive()
        ) 
开发者ID:altair-viz,项目名称:altair_pandas,代码行数:13,代码来源:_core.py

示例14: box

# 需要导入模块: import altair [as 别名]
# 或者: from altair import X [as 别名]
def box(self, vert=True, **kwargs):
        data = self._preprocess_data(with_index=False)
        chart = (
            alt.Chart(data)
            .transform_fold(list(data.columns), as_=["column", "value"])
            .mark_boxplot()
            .encode(x=alt.X("column:N", title=None), y="value:Q")
        )
        if not vert:
            chart.encoding.x, chart.encoding.y = chart.encoding.y, chart.encoding.x
        return chart 
开发者ID:altair-viz,项目名称:altair_pandas,代码行数:13,代码来源:_core.py

示例15: hist_frame

# 需要导入模块: import altair [as 别名]
# 或者: from altair import X [as 别名]
def hist_frame(self, column=None, layout=(-1, 2), **kwargs):
        if column is not None:
            if isinstance(column, str):
                column = [column]
        data = self._preprocess_data(with_index=False, usecols=column)
        data = data._get_numeric_data()
        nrows, ncols = _get_layout(data.shape[1], layout)
        return (
            alt.Chart(data, mark=self._get_mark_def("bar", kwargs))
            .encode(
                x=alt.X(alt.repeat("repeat"), type="quantitative", bin=True),
                y=alt.Y("count()", title="Frequency"),
            )
            .repeat(repeat=list(data.columns), columns=ncols)
        ) 
开发者ID:altair-viz,项目名称:altair_pandas,代码行数:17,代码来源:_core.py


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