.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_graphs/plot_graphs_fill_area.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_auto_graphs_plot_graphs_fill_area.py: How to fill an area =================== .. GENERATED FROM PYTHON SOURCE LINES 5-6 .. code-block:: Python # sphinx_gallery_thumbnail_number = 2 .. GENERATED FROM PYTHON SOURCE LINES 9-10 In this example, we show how to fill specified area with a given color. .. GENERATED FROM PYTHON SOURCE LINES 12-18 .. code-block:: Python import openturns as ot from openturns import viewer from matplotlib import pylab as plt ot.Log.Show(ot.Log.NONE) .. GENERATED FROM PYTHON SOURCE LINES 19-20 We generate a sample from a standard gaussian distribution. .. GENERATED FROM PYTHON SOURCE LINES 22-26 .. code-block:: Python dist = ot.Normal() graph = dist.drawPDF() view = viewer.View(graph) .. image-sg:: /auto_graphs/images/sphx_glr_plot_graphs_fill_area_001.png :alt: plot graphs fill area :srcset: /auto_graphs/images/sphx_glr_plot_graphs_fill_area_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 27-38 .. code-block:: Python def linearSample(xmin, xmax, npoints): """Returns a sample created from a regular grid from xmin to xmax with npoints points.""" step = (xmax - xmin) / (npoints - 1) rg = ot.RegularGrid(xmin, step, npoints) vertices = rg.getVertices() return vertices .. GENERATED FROM PYTHON SOURCE LINES 39-42 .. code-block:: Python a = 1.0 b = 2.0 .. GENERATED FROM PYTHON SOURCE LINES 43-48 .. code-block:: Python nplot = 100 # Number of points in the plot x = linearSample(a, b, nplot) y = dist.computePDF(x) .. GENERATED FROM PYTHON SOURCE LINES 49-50 Compute the bounds to fill: the lower vertical bound is 0 and the upper vertical bound is the PDF. .. GENERATED FROM PYTHON SOURCE LINES 53-56 .. code-block:: Python vLow = [0.0] * nplot vUp = [y[i, 0] for i in range(nplot)] .. GENERATED FROM PYTHON SOURCE LINES 57-59 .. code-block:: Python area = dist.computeCDF(b) - dist.computeCDF(a) .. GENERATED FROM PYTHON SOURCE LINES 60-68 .. code-block:: Python boundsPoly = ot.Polygon.FillBetween(x.asPoint(), vLow, vUp) graph = dist.drawPDF() graph.add(boundsPoly) graph.setTitle("Area = %.3f" % (area)) graph.setLegends([""]) view = viewer.View(graph) plt.show() .. image-sg:: /auto_graphs/images/sphx_glr_plot_graphs_fill_area_002.png :alt: Area = 0.136 :srcset: /auto_graphs/images/sphx_glr_plot_graphs_fill_area_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 69-70 The CDF difference is equal to the area under the curve. .. _sphx_glr_download_auto_graphs_plot_graphs_fill_area.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_graphs_fill_area.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_graphs_fill_area.py `