
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/02-production/2.8-plot_random_impact_angle.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

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

        :ref:`Go to the end <sphx_glr_download_auto_examples_02-production_2.8-plot_random_impact_angle.py>`
        to download the full example code.

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

.. _sphx_glr_auto_examples_02-production_2.8-plot_random_impact_angle.py:


Plot a distribution of random impact angles
===========================================

.. rubric:: By David Minton

This example demonstrates the generation of random impact angles.

.. GENERATED FROM PYTHON SOURCE LINES 10-52



.. image-sg:: /auto_examples/02-production/images/sphx_glr_2.8-plot_random_impact_angle_001.png
   :alt: Impact Angle Distribution
   :srcset: /auto_examples/02-production/images/sphx_glr_2.8-plot_random_impact_angle_001.png
   :class: sphx-glr-single-img





.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np

    from cratermaker.utils.montecarlo_utils import get_random_impact_angle

    # Sample data generation
    size = 10000
    angles = get_random_impact_angle(size=size)

    # Number of bins
    bins = 50
    observed_counts, bins_ang = np.histogram(angles, bins=bins, range=(0.0, 90.0))

    # Calculate expected distribution
    uniform_dist = np.linspace(0, 1, size)
    transformed_angles = np.rad2deg(np.arcsin(np.sqrt(uniform_dist)))
    expected_counts, _ = np.histogram(transformed_angles, bins=bins, range=(0.0, 90.0))

    # Plotting
    fig, ax = plt.subplots(figsize=(8, 4))

    # Observed counts
    ax.bar(
        bins_ang[:-1],
        observed_counts,
        width=np.diff(bins_ang),
        align="edge",
        label="Observed",
        alpha=0.5,
    )

    # Expected counts
    ax.plot(bins_ang[:-1], expected_counts, label="Expected", color="red")

    ax.set_xlabel("Impact Angle (deg)")
    ax.set_ylabel("Count")
    ax.legend()
    ax.set_title("Impact Angle Distribution")

    plt.tight_layout()
    plt.show()


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 0.300 seconds)


.. _sphx_glr_download_auto_examples_02-production_2.8-plot_random_impact_angle.py:

.. only:: html

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

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

      :download:`Download Jupyter notebook: 2.8-plot_random_impact_angle.ipynb <2.8-plot_random_impact_angle.ipynb>`

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

      :download:`Download Python source code: 2.8-plot_random_impact_angle.py <2.8-plot_random_impact_angle.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: 2.8-plot_random_impact_angle.zip <2.8-plot_random_impact_angle.zip>`


.. only:: html

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

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
