.. 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-7 .. code-block:: Python # sphinx_gallery_thumbnail_number = 2 .. GENERATED FROM PYTHON SOURCE LINES 10-11 In this example, we show how to fill specified area with a given color. .. GENERATED FROM PYTHON SOURCE LINES 13-19 .. 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 20-21 We generate a sample from the standard Normal distribution. .. GENERATED FROM PYTHON SOURCE LINES 23-27 .. 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 28-39 .. 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 40-43 .. code-block:: Python a = 1.0 b = 2.0 .. GENERATED FROM PYTHON SOURCE LINES 44-49 .. 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 50-51 Compute the bounds to fill: the lower vertical bound is 0 and the upper vertical bound is the PDF. .. GENERATED FROM PYTHON SOURCE LINES 54-57 .. code-block:: Python vLow = [0.0] * nplot vUp = [y[i, 0] for i in range(nplot)] .. GENERATED FROM PYTHON SOURCE LINES 58-60 .. code-block:: Python area = dist.computeCDF(b) - dist.computeCDF(a) .. GENERATED FROM PYTHON SOURCE LINES 61-69 .. 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 70-71 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 ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_graphs_fill_area.zip `