
:orphan:
:html_theme.sidebar_secondary.remove:

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

.. _gallery_scatter_with_labels:


Simple Scatter Plot with Labels
===============================
This example shows a basic scatter plot with labels created with Altair.


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


    import altair as alt
    import pandas as pd

    source = pd.DataFrame({
        'x': [1, 3, 5, 7, 9],
        'y': [1, 3, 5, 7, 9],
        'label': ['A', 'B', 'C', 'D', 'E']
    })

    points = alt.Chart(source).mark_point().encode(
        x='x:Q',
        y='y:Q'
    )

    text = points.mark_text(
        align='left',
        baseline='middle',
        dx=7
    ).encode(
        text='label'
    )

    points + text
    # No channel encoding options are specified in this chart
    # so the code is the same as for the method-based syntax.


.. tab-set::

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

        .. code:: python


            import altair as alt
            import pandas as pd

            source = pd.DataFrame({
                'x': [1, 3, 5, 7, 9],
                'y': [1, 3, 5, 7, 9],
                'label': ['A', 'B', 'C', 'D', 'E']
            })

            points = alt.Chart(source).mark_point().encode(
                x='x:Q',
                y='y:Q'
            )

            text = points.mark_text(
                align='left',
                baseline='middle',
                dx=7
            ).encode(
                text='label'
            )

            points + text


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

        .. code:: python


            import altair as alt
            import pandas as pd

            source = pd.DataFrame({
                'x': [1, 3, 5, 7, 9],
                'y': [1, 3, 5, 7, 9],
                'label': ['A', 'B', 'C', 'D', 'E']
            })

            points = alt.Chart(source).mark_point().encode(
                x='x:Q',
                y='y:Q'
            )

            text = points.mark_text(
                align='left',
                baseline='middle',
                dx=7
            ).encode(
                text='label'
            )

            points + text
            # No channel encoding options are specified in this chart
            # so the code is the same as for the method-based syntax.
