geocat.viz.util.set_titles_and_labels

geocat.viz.util.set_titles_and_labels#

geocat.viz.util.set_titles_and_labels(ax, maintitle=None, maintitlefontsize=18, subtitle=None, subtitlefontsize=18, lefttitle=None, lefttitlefontsize=18, righttitle=None, righttitlefontsize=18, xlabel=None, ylabel=None, labelfontsize=16)#

Utility function to handle axis titles, left/right aligned titles, and labels as they appear in NCL plots.

The intent of this function is to help make the plot look like an NCL plot as well as to help developers use only this convenience function instead of multiple matplotlib.axes.Axes functions, when applicable.

Parameters:
  • ax (matplotlib.axes.Axes, cartopy.mpl.geoaxes.GeoAxesSubplot) – Current axes to the current figure

  • maintitle (str) – Text to use for the maintitle.

  • maintitlefontsize (int) – Text font size for maintitle. A default value of 18 is used if nothing is set.

  • subtitle (str) – Text to use for an optional subtitle.

  • subtitlefontsize (int) – Text font size for subtitle. A default value of 18 is used if nothing is set.

  • lefttitle (str) – Text to use for an optional left-aligned title, if any. For most plots, only a maintitle is enough, but for some plot types, a lefttitle likely with a right-aligned title, righttitle, can be used together.

  • lefttitlefontsize (int) – Text font size for lefttitle. A default value of 18 is used if nothing is set.

  • righttitle (str) – Text to use for an optional right-aligned title, if any. For most plots, only a maintitle is enough, but for some plot types, a righttitle likely with a left-aligned title, lefttitle, can be used together.

  • righttitlefontsize (int) – Text font size for righttitle. A default value of 18 is used if nothing is set.

  • xlabel (str) – Text for the x-axis label.

  • ylabel (str) – Text for the y-axis label.

  • labelfontsize (int) – Text font size for x- and y-axes. A default value of 16 is used if nothing is set.

Notes

If no lefttitle and righttitle is set, maintitle is placed just top to the axes as follows:

>>>                  maintitle
>>>  ___________________________________________
>>> |                   Axes                    |
>>> |                                           |

If any of lefttitle or righttitle is set, lefttitle and righttitle are placed into a row that is just on top of the axes, and maintitle is placed on top of the row of lefttitle/righttitle as follows:

>>>                  maintitle
>>>  lefttitle                        righttitle
>>>  ___________________________________________
>>> |                   Axes                    |
>>> |                                           |

Be aware that the suptitle functionality does not always render well for Cartopy plots. If your main title appears too far above your plot, the recommended fix is to decrease the y-dimension of your figure size.

Examples

All usage examples are within the GeoCAT-Examples Gallery. To see more usage cases, search the function on the website.