.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/monte_carlo/03_radius_samplers.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_monte_carlo_03_radius_samplers.py: Comparing radius samplers ========================= Radius samplers are explicit physical inputs to an RSA simulation. Their ``to_bins`` method converts a continuous distribution into radius classes and number fractions for use by the analytical Percus--Yevick model. .. GENERATED FROM PYTHON SOURCE LINES 9-37 .. image-sg:: /gallery/monte_carlo/images/sphx_glr_03_radius_samplers_001.png :alt: Uniform, Log-normal :srcset: /gallery/monte_carlo/images/sphx_glr_03_radius_samplers_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from PackLab import samplers from PackLab.units import ureg uniform = samplers.UniformRadiusSampler( minimum_radius=80 * ureg.nanometer, maximum_radius=160 * ureg.nanometer, bins=8, ) log_normal = samplers.LogNormalRadiusSampler( median_radius=110 * ureg.nanometer, geometric_standard_deviation=1.25, maximum_radius_clip=250 * ureg.nanometer, bins=8, ) figure, axes = plt.subplots(1, 2, figsize=(9, 3.5), sharey=True) for axis, sampler, label in zip(axes, (uniform, log_normal), ("Uniform", "Log-normal")): _ = sampler.plot_histogram(ax=axis, color="tab:blue", width=7) axis.set_title(label) figure.tight_layout() assert np.isclose(sum(uniform.to_bins()[1]), 1.0) assert np.isclose(sum(log_normal.to_bins()[1]), 1.0) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.143 seconds) .. _sphx_glr_download_gallery_monte_carlo_03_radius_samplers.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 03_radius_samplers.ipynb <03_radius_samplers.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 03_radius_samplers.py <03_radius_samplers.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 03_radius_samplers.zip <03_radius_samplers.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_