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


Python altair.value方法代码示例

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


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

示例1: test_infer_encoding_types

# 需要导入模块: import altair [as 别名]
# 或者: from altair import value [as 别名]
def test_infer_encoding_types(channels):
    expected = dict(
        x=channels.X("xval"),
        y=channels.YValue("yval"),
        strokeWidth=channels.StrokeWidthValue(value=4),
    )

    # All positional args
    args, kwds = _getargs(
        channels.X("xval"), channels.YValue("yval"), channels.StrokeWidthValue(4)
    )
    assert infer_encoding_types(args, kwds, channels) == expected

    # All keyword args
    args, kwds = _getargs(x="xval", y=alt.value("yval"), strokeWidth=alt.value(4))
    assert infer_encoding_types(args, kwds, channels) == expected

    # Mixed positional & keyword
    args, kwds = _getargs(
        channels.X("xval"), channels.YValue("yval"), strokeWidth=alt.value(4)
    )
    assert infer_encoding_types(args, kwds, channels) == expected 
开发者ID:altair-viz,项目名称:altair,代码行数:24,代码来源:test_core.py

示例2: altair_step_matrix

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

示例3: test_infer_dtype

# 需要导入模块: import altair [as 别名]
# 或者: from altair import value [as 别名]
def test_infer_dtype(value, expected_type):
    assert infer_dtype(value) == expected_type 
开发者ID:altair-viz,项目名称:altair,代码行数:4,代码来源:test_core.py

示例4: test_infer_encoding_types_with_condition

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

示例5: area

# 需要导入模块: import altair [as 别名]
# 或者: from altair import value [as 别名]
def area(self) -> float:
        """Returns the area of the shape, in square meters.
        The shape is projected to an equivalent local projection before
        computing a value.
        """
        return self.project_shape().area

    # --- Representations --- 
开发者ID:xoolive,项目名称:traffic,代码行数:10,代码来源:mixins.py

示例6: geoencode

# 需要导入模块: import altair [as 别名]
# 或者: from altair import value [as 别名]
def geoencode(self) -> alt.Chart:  # coverage: ignore
        """Returns an `altair <http://altair-viz.github.io/>`_ encoding of the
        shape to be composed in an interactive visualization.
        """
        return (
            alt.Chart(self.data)
            .mark_circle()
            .encode(
                longitude="longitude:Q",
                latitude="latitude:Q",
                size=alt.value(3),
                color=alt.value("steelblue"),
            )
        ) 
开发者ID:xoolive,项目名称:traffic,代码行数:16,代码来源:mixins.py

示例7: airline_chart

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

示例8: airport_chart

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

示例9: mirror

# 需要导入模块: import altair [as 别名]
# 或者: from altair import value [as 别名]
def mirror(spec_top: MsmsSpectrum, spec_bottom: MsmsSpectrum,
           spectrum_kws: Optional[Dict] = None, *_) -> altair.LayerChart:
    """
    Mirror plot two MS/MS spectra.

    Parameters
    ----------
    spec_top : MsmsSpectrum
        The spectrum to be plotted on the top.
    spec_bottom : MsmsSpectrum
        The spectrum to be plotted on the bottom.
    spectrum_kws : Optional[Dict], optional
        Keyword arguments for `iplot.spectrum`.
    *_
        Ignored, for consistency with the `plot.mirror` API.

    Returns
    -------
    altair.LayerChart
        The Altair chart instance with the plotted spectrum.
    """
    if spectrum_kws is None:
        spectrum_kws = {}
    # Top spectrum.
    spec_plot = spectrum(spec_top, mirror_intensity=False, **spectrum_kws)
    # Mirrored bottom spectrum.
    spec_plot += spectrum(spec_bottom, mirror_intensity=True, **spectrum_kws)

    spec_plot += (altair.Chart(pd.DataFrame({'sep': [0]}))
                  .mark_rule(size=3).encode(
                      y='sep', color=altair.value('lightGray')))

    return spec_plot 
开发者ID:bittremieux,项目名称:spectrum_utils,代码行数:35,代码来源:iplot.py

示例10: heatmap

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

示例11: line

# 需要导入模块: import altair [as 别名]
# 或者: from altair import value [as 别名]
def line(self, alpha=None, width=450, height=300, ax=None, **kwds):
        """Line plot for Series data

        >>> series.vgplot.line()  # doctest: +SKIP

        Parameters
        ----------
        alpha : float, optional
            transparency level, 0 <= alpha <= 1
        width : int, optional
            the width of the plot in pixels
        height : int, optional
            the height of the plot in pixels
        ax: altair.Chart, optional
            chart to be overlayed with this vis (convinience method for `chart1 + chart2`)

        Returns
        -------
        chart : altair.Chart
            The altair plot representation
        """
        df = self._data.reset_index()
        df.columns = map(str, df.columns)
        x, y = df.columns

        chart = self._plot(
            data=df,
            width=width,
            height=height,
            title=kwds.pop("title", ""),
            figsize=kwds.pop("figsize", None),
            dpi=kwds.pop("dpi", None),
        )

        chart = chart.mark_line().encode(x=_x(x, df), y=_y(y, df))

        if alpha is not None:
            assert 0 <= alpha <= 1
            chart = chart.encode(opacity=alt.value(alpha))

        if ax is not None:
            return ax + chart

        warn_if_keywords_unused("line", kwds)
        return chart 
开发者ID:altair-viz,项目名称:pdvega,代码行数:47,代码来源:_core.py

示例12: area

# 需要导入模块: import altair [as 别名]
# 或者: from altair import value [as 别名]
def area(self, alpha=None, width=450, height=300, ax=None, **kwds):
        """Area plot for Series data

        >>> series.vgplot.area()  # doctest: +SKIP

        Parameters
        ----------
        alpha : float, optional
            transparency level, 0 <= alpha <= 1
        width : int, optional
            the width of the plot in pixels
        height : int, optional
            the height of the plot in pixels
        ax: altair.Chart, optional
            chart to be overlayed with this vis (convinience method for `chart1 + chart2`)

        Returns
        -------
        chart : alt.Chart
            altair chart representation
        """
        df = self._data.reset_index()
        df.columns = map(str, df.columns)
        x, y = df.columns

        chart = self._plot(
            data=df,
            width=width,
            height=height,
            title=kwds.pop("title", ""),
            figsize=kwds.pop("figsize", None),
            dpi=kwds.pop("dpi", None),
        ).mark_area().encode(
            x=_x(x, df), y=_y(y, df)
        )

        if alpha is not None:
            assert 0 <= alpha <= 1
            chart = chart.encode(opacity=alt.value(alpha))

        if ax is not None:
            return ax + chart

        warn_if_keywords_unused("area", kwds)
        return chart 
开发者ID:altair-viz,项目名称:pdvega,代码行数:47,代码来源:_core.py

示例13: bar

# 需要导入模块: import altair [as 别名]
# 或者: from altair import value [as 别名]
def bar(self, alpha=None, width=450, height=300, ax=None, **kwds):
        """Bar plot for Series data

        >>> series.vgplot.bar()  # doctest: +SKIP

        Parameters
        ----------
        alpha : float, optional
            transparency level, 0 <= alpha <= 1
        width : int, optional
            the width of the plot in pixels
        height : int, optional
            the height of the plot in pixels
        ax: altair.Chart, optional
            chart to be overlayed with this vis (convinience method for `chart1 + chart2`)

        Returns
        -------
        chart : alt.Chart
            altair chart representation
        """

        df = self._data.reset_index()
        df.columns = map(str, df.columns)
        x, y = df.columns

        chart = self._plot(
            data=df,
            width=width,
            height=height,
            title=kwds.pop("title", ""),
            figsize=kwds.pop("figsize", None),
            dpi=kwds.pop("dpi", None),
        ).mark_bar().encode(
            x=_x(x, df), y=_y(y, df)
        )

        if alpha is not None:
            assert 0 <= alpha <= 1
            chart = chart.encode(opacity=alt.value(alpha))

        if ax is not None:
            return ax + chart

        warn_if_keywords_unused("bar", kwds)
        return chart 
开发者ID:altair-viz,项目名称:pdvega,代码行数:48,代码来源:_core.py

示例14: scatter

# 需要导入模块: import altair [as 别名]
# 或者: from altair import value [as 别名]
def scatter(
        self, x, y, c=None, s=None, alpha=None, width=450, height=300, ax=None, **kwds
    ):
        """Scatter plot for DataFrame data

        >>> dataframe.vgplot.scatter(x, y)  # doctest: +SKIP

        Parameters
        ----------
        x : string
            the column to use as the x-axis variable.
        y : string
            the column to use as the y-axis variable.
        c : string, optional
            the column to use to encode the color of the points
        s : string, optional
            the column to use to encode the size of the points
        alpha : float, optional
            transparency level, 0 <= alpha <= 1
        width : int, optional
            the width of the plot in pixels
        height : int, optional
            the height of the plot in pixels
        ax: altair.Chart, optional
            chart to be overlayed with this vis (convinience method for `chart1 + chart2`)

        Returns
        -------
        chart : alt.Chart
            altair chart representation
        """
        df = self._data

        chart = self._plot(
            width=width,
            height=height,
            title=kwds.pop("title", ""),
            figsize=kwds.pop("figsize", None),
            dpi=kwds.pop("dpi", None),
        ).mark_point().encode(
            x=_x(x, df, ordinal_threshold=0), y=_y(y, df, ordinal_threshold=0)
        )

        if alpha is not None:
            assert 0 <= alpha <= 1
            chart = chart.encode(opacity=alt.value(alpha))

        if c is not None:
            chart.encoding["color"] = {"field": c, "type": infer_vegalite_type(df[c])}

        if s is not None:
            chart.encoding["size"] = {"field": s, "type": infer_vegalite_type(df[s])}

        if ax is not None:
            return ax + chart

        warn_if_keywords_unused("scatter", kwds)
        return chart 
开发者ID:altair-viz,项目名称:pdvega,代码行数:60,代码来源:_core.py

示例15: boxplot_vertical

# 需要导入模块: import altair [as 别名]
# 或者: from altair import value [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.value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。