.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_probabilistic_modeling/distributions/plot_create_and_draw_scalar_distributions.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_probabilistic_modeling_distributions_plot_create_and_draw_scalar_distributions.py: Create and draw scalar distributions ==================================== .. GENERATED FROM PYTHON SOURCE LINES 6-14 .. code-block:: default from __future__ import print_function import openturns as ot import openturns.viewer as viewer from matplotlib import pylab as plt ot.Log.Show(ot.Log.NONE) .. GENERATED FROM PYTHON SOURCE LINES 15-23 A continuous distribution ------------------------- We build a normal distribution with parameters : .. math:: \mu = 2.2, \sigma = 0.6 .. GENERATED FROM PYTHON SOURCE LINES 23-26 .. code-block:: default distribution = ot.Normal(2.2, 0.6) print(distribution) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Normal(mu = 2.2, sigma = 0.6) .. GENERATED FROM PYTHON SOURCE LINES 27-28 We can draw a sample following this distribution with the `getSample` method : .. GENERATED FROM PYTHON SOURCE LINES 28-32 .. code-block:: default size = 10 sample = distribution.getSample(size) print(sample) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none [ X0 ] 0 : [ 2.90698 ] 1 : [ 2.4694 ] 2 : [ 2.37417 ] 3 : [ 2.69831 ] 4 : [ 2.28606 ] 5 : [ 2.08412 ] 6 : [ 2.87742 ] 7 : [ 1.80004 ] 8 : [ 1.67943 ] 9 : [ 2.99115 ] .. GENERATED FROM PYTHON SOURCE LINES 33-34 We draw its PDF and CDF : .. GENERATED FROM PYTHON SOURCE LINES 34-38 .. code-block:: default graphPDF = distribution.drawPDF() graphPDF.setTitle(r"PDF of a normal distribution with parameters $\mu = 2.2$ and $\sigma = 0.6$") view = viewer.View(graphPDF) .. image:: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_create_and_draw_scalar_distributions_001.png :alt: PDF of a normal distribution with parameters $\mu = 2.2$ and $\sigma = 0.6$ :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 39-44 .. code-block:: default graphCDF = distribution.drawCDF() graphCDF.setTitle(r"CDF of a normal distribution with parameters $\mu = 2.2$ and $\sigma = 0.6$") view = viewer.View(graphCDF) .. image:: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_create_and_draw_scalar_distributions_002.png :alt: CDF of a normal distribution with parameters $\mu = 2.2$ and $\sigma = 0.6$ :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 45-49 A discrete distribution ----------------------- We define a geometric distribution with parameter :math:`p = 0.7`. .. GENERATED FROM PYTHON SOURCE LINES 49-53 .. code-block:: default p = 0.7 distribution = ot.Geometric(p) print(distribution) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Geometric(p = 0.7) .. GENERATED FROM PYTHON SOURCE LINES 54-55 We draw a sample of it : .. GENERATED FROM PYTHON SOURCE LINES 55-59 .. code-block:: default size = 10 sample = distribution.getSample(size) print(sample) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none [ X0 ] 0 : [ 3 ] 1 : [ 1 ] 2 : [ 1 ] 3 : [ 2 ] 4 : [ 1 ] 5 : [ 2 ] 6 : [ 1 ] 7 : [ 1 ] 8 : [ 1 ] 9 : [ 2 ] .. GENERATED FROM PYTHON SOURCE LINES 60-61 We draw its PDF and its CDF : .. GENERATED FROM PYTHON SOURCE LINES 61-65 .. code-block:: default graphPDF = distribution.drawPDF() graphPDF.setTitle(r"PDF of a geometric distribution with parameter $p = 0.7$") view = viewer.View(graphPDF) .. image:: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_create_and_draw_scalar_distributions_003.png :alt: PDF of a geometric distribution with parameter $p = 0.7$ :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 66-70 .. code-block:: default graphCDF = distribution.drawCDF() graphCDF.setTitle(r"CDF of a geometric distribution with parameter $p = 0.7$") view = viewer.View(graphCDF) .. image:: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_create_and_draw_scalar_distributions_004.png :alt: CDF of a geometric distribution with parameter $p = 0.7$ :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 71-76 Conclusion ---------- The two previous examples look very similar despite their continuous and discrete nature. In the library there is no distinction between continuous and discrete distributions. .. GENERATED FROM PYTHON SOURCE LINES 78-79 Display all figures .. GENERATED FROM PYTHON SOURCE LINES 79-80 .. code-block:: default plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.422 seconds) .. _sphx_glr_download_auto_probabilistic_modeling_distributions_plot_create_and_draw_scalar_distributions.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: plot_create_and_draw_scalar_distributions.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_create_and_draw_scalar_distributions.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_