.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples/tutorial/plot_sample_02.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__examples_tutorial_plot_sample_02.py: Plotting a gaussian (tutorial) ============================== Example ``matplotlib`` to plot a gaussian. .. GENERATED FROM PYTHON SOURCE LINES 9-10 Let's import numpy and matplotlib .. GENERATED FROM PYTHON SOURCE LINES 10-14 .. code-block:: default :lineno-start: 10 import numpy as np import matplotlib.pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 15-19 ------------------------------------- Methods ------------------------------------- First, lets define the gaussian method .. GENERATED FROM PYTHON SOURCE LINES 19-23 .. code-block:: default :lineno-start: 19 def gaussian(x, mu=0, sig=1): return np.exp(-np.power(x - mu, 2.) / (2 * np.power(sig, 2.))) .. GENERATED FROM PYTHON SOURCE LINES 24-28 --------------------------- Main --------------------------- Lets create the x and y values .. GENERATED FROM PYTHON SOURCE LINES 28-31 .. code-block:: default :lineno-start: 28 x = np.linspace(-3, 3, 120) y = gaussian(x) .. GENERATED FROM PYTHON SOURCE LINES 32-33 Lets plot using matplotlib .. GENERATED FROM PYTHON SOURCE LINES 33-34 .. code-block:: default :lineno-start: 33 plt.plot(x, y) plt.show() .. image:: /_examples/tutorial/images/sphx_glr_plot_sample_02_001.png :alt: plot sample 02 :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.091 seconds) .. _sphx_glr_download__examples_tutorial_plot_sample_02.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_sample_02.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_sample_02.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_