.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery_examples/maps/add_colorbar.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_gallery_examples_maps_add_colorbar.py: .. _example_colorbar: Add a colorbar to a map ####################### Example showing how to quickly add a colorbar to a map plot. Even though adding a colorbar using `~matplotlib` syntax directly is very straightforward, `~madcubapy` functions offer additional functionality and let the user quickly add the colorbar using only one line of code. We can add a colorbar by using :func:`~madcubapy.visualization.add_colorbar` or :func:`~madcubapy.visualization.insert_colorbar`. Both functions accept a number of additional parameters that are passed to :func:`matplotlib.pyplot.colorbar`. With this we can set custom ticks, a custom label, etc. Check the :ref:`Colorbar page ` to know more about how these two functions work. .. GENERATED FROM PYTHON SOURCE LINES 24-41 .. image-sg:: /gallery_examples/maps/images/sphx_glr_add_colorbar_001.png :alt: IRAS16293_SO_2-1_moment0_madcuba.fits :srcset: /gallery_examples/maps/images/sphx_glr_add_colorbar_001.png :class: sphx-glr-single-img .. code-block:: Python from madcubapy.io import MadcubaMap from madcubapy.visualization import insert_colorbar from madcubapy.visualization import add_wcs_axes import matplotlib.pyplot as plt # Read fits file madcuba_map = MadcubaMap.read("../data/IRAS16293_SO_2-1_moment0_madcuba.fits") fig = plt.figure(figsize=(6,5)) ax, img = add_wcs_axes(fig, 1, 1, 1, fitsmap=madcuba_map, vmin=0, vmax=100) # Add the colorbar. We can pass kwargs to matplotlib.Figure.colorbar() insert_colorbar(ax, label='Custom label') plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.110 seconds) .. _sphx_glr_download_gallery_examples_maps_add_colorbar.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: add_colorbar.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: add_colorbar.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: add_colorbar.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_