.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/gridlines_and_labels/tick_labels.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_gridlines_and_labels_tick_labels.py: Tick Labels ----------- This example demonstrates adding tick labels to maps on rectangular projections using special tick formatters. .. GENERATED FROM PYTHON SOURCE LINES 9-50 .. image-sg:: /gallery/gridlines_and_labels/images/sphx_glr_tick_labels_001.png :alt: tick labels :srcset: /gallery/gridlines_and_labels/images/sphx_glr_tick_labels_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import cartopy.crs as ccrs from cartopy.mpl.ticker import LatitudeFormatter, LongitudeFormatter def main(): fig = plt.figure(figsize=(8, 10)) # Label axes of a Plate Carree projection with a central longitude of 180: ax1 = fig.add_subplot(2, 1, 1, projection=ccrs.PlateCarree(central_longitude=180)) ax1.set_global() ax1.coastlines() ax1.set_xticks([0, 60, 120, 180, 240, 300, 360], crs=ccrs.PlateCarree()) ax1.set_yticks([-90, -60, -30, 0, 30, 60, 90], crs=ccrs.PlateCarree()) lon_formatter = LongitudeFormatter(zero_direction_label=True) lat_formatter = LatitudeFormatter() ax1.xaxis.set_major_formatter(lon_formatter) ax1.yaxis.set_major_formatter(lat_formatter) # Label axes of a Mercator projection without degree symbols in the labels # and formatting labels to include 1 decimal place: ax2 = fig.add_subplot(2, 1, 2, projection=ccrs.Mercator()) ax2.set_global() ax2.coastlines() ax2.set_xticks([-180, -120, -60, 0, 60, 120, 180], crs=ccrs.PlateCarree()) ax2.set_yticks([-78.5, -60, -25.5, 25.5, 60, 80], crs=ccrs.PlateCarree()) lon_formatter = LongitudeFormatter(number_format='.1f', degree_symbol='', dateline_direction_label=True) lat_formatter = LatitudeFormatter(number_format='.1f', degree_symbol='') ax2.xaxis.set_major_formatter(lon_formatter) ax2.yaxis.set_major_formatter(lat_formatter) plt.show() if __name__ == '__main__': main() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.592 seconds) .. _sphx_glr_download_gallery_gridlines_and_labels_tick_labels.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: tick_labels.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: tick_labels.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_