.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_intro_summary-exercises_auto_examples_plot_optimize_lidar_complex_data_fit.py: The lidar system, data and fit (2 of 2 datasets) ================================================ Generate a chart of the data fitted by Gaussian curve .. image:: /intro/summary-exercises/auto_examples/images/sphx_glr_plot_optimize_lidar_complex_data_fit_001.png :class: sphx-glr-single-img .. code-block:: python import numpy as np import matplotlib.pyplot as plt from scipy.optimize import leastsq def model(t, coeffs): return coeffs[0] + \ coeffs[1] * np.exp(-((t-coeffs[2])/coeffs[3])**2) + \ coeffs[4] * np.exp(-((t-coeffs[5])/coeffs[6])**2) + \ coeffs[7] * np.exp(-((t-coeffs[8])/coeffs[9])**2) def residuals(coeffs, y, t): return y - model(t, coeffs) waveform_2 = np.load('waveform_2.npy') t = np.arange(len(waveform_2)) x0 = np.array([3, 30, 20, 1, 12, 25, 1, 8, 28, 1], dtype=float) x, flag = leastsq(residuals, x0, args=(waveform_2, t)) fig, ax = plt.subplots(figsize=(8, 6)) plt.plot(t, waveform_2, t, model(t, x)) plt.xlabel('Time [ns]') plt.ylabel('Amplitude [bins]') plt.legend(['Waveform', 'Model']) plt.show() **Total running time of the script:** ( 0 minutes 0.021 seconds) .. _sphx_glr_download_intro_summary-exercises_auto_examples_plot_optimize_lidar_complex_data_fit.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: plot_optimize_lidar_complex_data_fit.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_optimize_lidar_complex_data_fit.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_