
:orphan:
:html_theme.sidebar_secondary.remove:

.. This document is auto-generated by the altair-gallery extension. Do not modify directly.

.. _gallery_errorbars_with_ci:


Error Bars with Confidence Interval
======================================
This example shows how to show error bars using confidence intervals.
The confidence intervals are computed internally in vega by a non-parametric
`bootstrap of the mean <https://github.com/vega/vega-statistics/blob/master/src/bootstrapCI.js>`_.


.. altair-plot::
    :remove-code:
    


    import altair as alt
    from altair.datasets import data

    source = data.barley()

    error_bars = alt.Chart(source).mark_errorbar(extent='ci').encode(
      x=alt.X('yield:Q', scale=alt.Scale(zero=False)),
      y=alt.Y('variety:N')
    )

    points = alt.Chart(source).mark_point(filled=True, color='black').encode(
      x=alt.X('yield:Q', aggregate='mean'),
      y=alt.Y('variety:N'),
    )

    error_bars + points


.. tab-set::

    .. tab-item:: Method syntax
        :sync: method

        .. code:: python


            import altair as alt
            from altair.datasets import data

            source = data.barley()

            error_bars = alt.Chart(source).mark_errorbar(extent='ci').encode(
              alt.X('yield').scale(zero=False),
              alt.Y('variety')
            )

            points = alt.Chart(source).mark_point(filled=True, color='black').encode(
              x=alt.X('mean(yield)'),
              y=alt.Y('variety'),
            )

            error_bars + points


    .. tab-item:: Attribute syntax
        :sync: attribute

        .. code:: python


            import altair as alt
            from altair.datasets import data

            source = data.barley()

            error_bars = alt.Chart(source).mark_errorbar(extent='ci').encode(
              x=alt.X('yield:Q', scale=alt.Scale(zero=False)),
              y=alt.Y('variety:N')
            )

            points = alt.Chart(source).mark_point(filled=True, color='black').encode(
              x=alt.X('yield:Q', aggregate='mean'),
              y=alt.Y('variety:N'),
            )

            error_bars + points
