.. note::
    :class: sphx-glr-download-link-note

    Click :ref:`here <sphx_glr_download_gallery_lines_bars_and_markers_scatter_with_legend.py>` to download the full example code
.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_lines_bars_and_markers_scatter_with_legend.py:


===========================
Scatter plots with a legend
===========================

Also demonstrates how transparency of the markers
can be adjusted by giving ``alpha`` a value between
0 and 1.




.. image:: /gallery/lines_bars_and_markers/images/sphx_glr_scatter_with_legend_001.png
    :class: sphx-glr-single-img





.. code-block:: python


    import matplotlib.pyplot as plt
    from numpy.random import rand


    fig, ax = plt.subplots()
    for color in ['red', 'green', 'blue']:
        n = 750
        x, y = rand(2, n)
        scale = 200.0 * rand(n)
        ax.scatter(x, y, c=color, s=scale, label=color,
                   alpha=0.3, edgecolors='none')

    ax.legend()
    ax.grid(True)

    plt.show()


.. _sphx_glr_download_gallery_lines_bars_and_markers_scatter_with_legend.py:


.. only :: html

 .. container:: sphx-glr-footer
    :class: sphx-glr-footer-example



  .. container:: sphx-glr-download

     :download:`Download Python source code: scatter_with_legend.py <scatter_with_legend.py>`



  .. container:: sphx-glr-download

     :download:`Download Jupyter notebook: scatter_with_legend.ipynb <scatter_with_legend.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    Keywords: matplotlib code example, codex, python plot, pyplot
    `Gallery generated by Sphinx-Gallery
    <https://sphinx-gallery.readthedocs.io>`_
