
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/lines_bars_and_markers/scatter_piecharts.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

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

        Click :ref:`here <sphx_glr_download_gallery_lines_bars_and_markers_scatter_piecharts.py>`
        to download the full example code

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_lines_bars_and_markers_scatter_piecharts.py:


===================================
Scatter plot with pie chart markers
===================================

This example makes custom 'pie charts' as the markers for a scatter plot.

Thanks to Manuel Metz for the example.

.. GENERATED FROM PYTHON SOURCE LINES 10-45

.. code-block:: default


    import numpy as np
    import matplotlib.pyplot as plt

    # first define the ratios
    r1 = 0.2       # 20%
    r2 = r1 + 0.4  # 40%

    # define some sizes of the scatter marker
    sizes = np.array([60, 80, 120])

    # calculate the points of the first pie marker
    # these are just the origin (0, 0) + some (cos, sin) points on a circle
    x1 = np.cos(2 * np.pi * np.linspace(0, r1))
    y1 = np.sin(2 * np.pi * np.linspace(0, r1))
    xy1 = np.row_stack([[0, 0], np.column_stack([x1, y1])])
    s1 = np.abs(xy1).max()

    x2 = np.cos(2 * np.pi * np.linspace(r1, r2))
    y2 = np.sin(2 * np.pi * np.linspace(r1, r2))
    xy2 = np.row_stack([[0, 0], np.column_stack([x2, y2])])
    s2 = np.abs(xy2).max()

    x3 = np.cos(2 * np.pi * np.linspace(r2, 1))
    y3 = np.sin(2 * np.pi * np.linspace(r2, 1))
    xy3 = np.row_stack([[0, 0], np.column_stack([x3, y3])])
    s3 = np.abs(xy3).max()

    fig, ax = plt.subplots()
    ax.scatter(range(3), range(3), marker=xy1, s=s1**2 * sizes, facecolor='blue')
    ax.scatter(range(3), range(3), marker=xy2, s=s2**2 * sizes, facecolor='green')
    ax.scatter(range(3), range(3), marker=xy3, s=s3**2 * sizes, facecolor='red')

    plt.show()




.. image:: /gallery/lines_bars_and_markers/images/sphx_glr_scatter_piecharts_001.png
    :alt: scatter piecharts
    :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 46-53

------------

References
""""""""""

The use of the following functions, methods, classes and modules is shown
in this example:

.. GENERATED FROM PYTHON SOURCE LINES 54-58

.. code-block:: default


    import matplotlib
    matplotlib.axes.Axes.scatter
    matplotlib.pyplot.scatter




.. rst-class:: sphx-glr-script-out

 Out:

 .. code-block:: none


    <function scatter at 0x7f73be8291f0>




.. _sphx_glr_download_gallery_lines_bars_and_markers_scatter_piecharts.py:


.. only :: html

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



  .. container:: sphx-glr-download sphx-glr-download-python

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



  .. container:: sphx-glr-download sphx-glr-download-jupyter

     :download:`Download Jupyter notebook: scatter_piecharts.ipynb <scatter_piecharts.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>`_
