.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "modeling/gallery/spectral/plot_constant_spectral.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_modeling_gallery_spectral_plot_constant_spectral.py: .. _constant-spectral-model: Constant spectral model ======================= This model takes a constant value along the spectral range. .. math:: \phi(E) = k .. GENERATED FROM PYTHON SOURCE LINES 13-16 Example plot ------------ Here is an example plot of the model: .. GENERATED FROM PYTHON SOURCE LINES 16-26 .. code-block:: default from astropy import units as u import matplotlib.pyplot as plt from gammapy.modeling.models import ConstantSpectralModel, Models, SkyModel energy_bounds = [0.1, 100] * u.TeV model = ConstantSpectralModel(const="1 / (cm2 s TeV)") model.plot(energy_bounds) plt.grid(which="both") .. image-sg:: /modeling/gallery/spectral/images/sphx_glr_plot_constant_spectral_001.png :alt: plot constant spectral :srcset: /modeling/gallery/spectral/images/sphx_glr_plot_constant_spectral_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 27-30 YAML representation ------------------- Here is an example YAML file using the model: .. GENERATED FROM PYTHON SOURCE LINES 30-35 .. code-block:: default model = SkyModel(spectral_model=model, name="constant-model") models = Models([model]) print(models.to_yaml()) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none components: - name: constant-model type: SkyModel spectral: type: ConstantSpectralModel parameters: - name: const value: 1.0 unit: cm-2 s-1 TeV-1 .. _sphx_glr_download_modeling_gallery_spectral_plot_constant_spectral.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_constant_spectral.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_constant_spectral.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_