text2plot#
Write text on a plot
This module was written by Matthias Cuntz while at Department of Computational Hydrosystems, Helmholtz Centre for Environmental Research - UFZ, Leipzig, Germany, and continued while at Institut National de Recherche pour l’Agriculture, l’Alimentation et l’Environnement (INRAE), Nancy, France.
- copyright:
Copyright 2014-2022 Matthias Cuntz, see AUTHORS.rst for details.
- license:
MIT License, see LICENSE for details.
The following functions are provided:
|
Write text on plot |
|
Write a, B, iii, IV, e), etc. |
|
Write a copyright notice on a plot |
- History
Written Nov 2021 by Matthias Cuntz (mc (at) macu (dot) de) combining abc2plot and signature2plot
Written abc2plot, May 2012, Matthias Cuntz
Added parenthesis option to abc2plot, Feb 2013, Arndt Piayda
Ported to Python 3, Feb 2013, Matthias Cuntz
Added opening and closing parentheses, brackets, braces, Feb 2013, Matthias Cuntz
Options usetex and mathrm, Feb 2013, Matthias Cuntz
Options mathbf, large and making medium the default, Feb 2013, Matthias Cuntz
Added string option, Nov 2013, Matthias Cuntz
Corrected bug in medium as default, Nov 2013, Matthias Cuntz
Make usetex work with fontsize keyword of axis.text() of matplotllib v1.1.0, Nov 2013, Matthias Cuntz
Written signature2plot, Jan 2014, Matthias Cuntz
Assert that small or large is set if medium is not None (abc2plot), Feb 2014, Matthias Cuntz
Replace horizontalalignment=’left’ and verticalalignment=’bottom’ by kwargs mechanism (abc2plot), May 2014, Matthias Cuntz
Added option italic (abc2plot), May 2014, Matthias Cuntz
Added options xlarge, xxlarge, xsmall, xxsmall (abc2plot), Oct 2015, Matthias Cuntz
Make numpy docstring format (abc2plot), Nov 2020, Matthias Cuntz
Ported into pyjams, Nov 2021, Matthias Cuntz
dx, dy, and name mandatory parameters (signature2plot), Nov 2020, Matthias Cuntz
Change option name parenthesis -> parentheses, Nov 2021, Matthias Cuntz
Written text2plot, Nov 2021, Matthias Cuntz
Use text2plot for signature2plot, Nov 2021, Matthias Cuntz
Use text2plot for abc2plot, Nov 2021, Matthias Cuntz
More consistent docstrings, Jan 2022, Matthias Cuntz
Added upper keyword in abc2plot, Jun 2024, Matthias Cuntz
- abc2plot(handle, dx, dy, iplot, integer=False, roman=False, lower=False, upper=None, parentheses=None, brackets=None, braces=None, bold=False, italic=False, usetex=False, mathrm=False, string=False, **kwargs)[source]#
Write a, B, iii, IV, e), etc. on plots
- Parameters:
handle (
matplotlib.axes
subclass) – Matplotlib axes handledx (float) – % of xlim from min(xlim)
dy (float) – % of ylim from min(ylim)
iplot (int or str) – Number of plot starting with 1, or string if ‘string==True’
integer (bool, optional) – Use integers instead of a, b, c if True (default: False)
roman (bool, optional) – Use Roman literals instead of a, b, c if True (default: False)
lower (bool, optional) – Use lowercase letters for a, b, c if True, else use uppercase letters (default). lower=True and upper=True are mutually exclusive.
upper (bool, optional) – Use uppercase letters for A, B, C if True (default), else use lowercase letters. lower=True and upper=True are mutually exclusive.
parentheses (str or None, optional) – Parentheses before or after the letter/number. Possible values are ‘open’, ‘close’, ‘both’, ‘None’, and None. ‘open’ puts opening parentheses in front of the letter/number. ‘close’ puts closing parentheses after the letter/number. ‘both’ puts opening and closing parentheses around the letter/number. ‘None’ and None do not put any parentheses before or after the letter/number (default).
brackets (str or None, optional) – Brackets before or after the letter/number. Possible values are ‘open’, ‘close’, ‘both’, ‘None’, and None. ‘open’ puts opening brackets in front of the letter/number. ‘close’ puts closing brackets after the letter/number. ‘both’ puts opening and closing brackets around the letter/number. ‘None’ and None do not put any brackets before or after the letter/number (default).
braces (str or None, optional) – Braces before or after the letter/number. Possible values are ‘open’, ‘close’, ‘both’, ‘None’, and None. ‘open’ puts opening braces in front of the letter/number. ‘close’ puts closing braces after the letter/number. ‘both’ puts opening and closing braces around the letter/number. ‘None’ and None do not put any braces before or after the letter/number (default).
bold (bool, optional) – fontweight=’bold’ if True, else fontsize=’normal’ (default)
italic (bool, optional) – fontstyle=’italic’ if True, else fontstyle=’normal’ (default)
usetex (bool, optional) – Embed into LaTeX math environment if True, else no LaTeX math mode (default)
mathrm (bool, optional) – If True, put text into appropriate LaTeX mathrm/mathit/mathbf environment if usetex==True and italic==True or bold==True. If False, use standard math font if usetex==True (default).
string (bool, optional) – Treat iplot as literal string and not as integer if True (default: False). integer, roman and lower are disabled then.
**kwargs (dict, optional) – All additional parameters are passed passed to
text2plot()
- Return type:
Letter/number or string on plot
Notes
If output is a letter then iplot > 26 gives unexpected results.
Examples
abc2plot(ax, 0.7, 0.6, 2, large=True, parentheses='both', usetex=usetex, mathrm=False)
- signature2plot(handle, dx, dy, itext, **kwargs)[source]#
Write a copyright notice on a plot
The notice is: ‘(C) YYYY itext’, where YYYY is the current 4-digit year.
- Parameters:
handle (
matplotlib.axes
subclass) – Matplotlib axes handledx (float) – % of xlim from min(xlim)
dy (float) – % of ylim from min(ylim)
itext (str) – Text after ‘(C) YYYY’, where YYYY is the current 4-digit year
**kwargs (dict, optional) – All additional parameters are passed passed to
text2plot()
- Return type:
‘(C) YYYY itext’ or ‘(C) YYYY’ on plot, where YYYY is the 4-digit year
Notes
Signature will be right-aligned horizontally if horizontalalignment or ha are not given in kwargs.
Examples
signature2plot(ax, 0., 0.05, 'M Cuntz, INRAE', small=True, italic=True, usetex=usetex, mathrm=True)
- text2plot(handle, dx, dy, itext, small=False, medium=False, large=False, xsmall=False, xxsmall=False, xlarge=False, xxlarge=False, bold=False, italic=False, usetex=False, mathrm=False, **kwargs)[source]#
Write text on plot
- Parameters:
handle (
matplotlib.axes
subclass) – Matplotlib axes handledx (float) – % of xlim from min(xlim)
dy (float) – % of ylim from min(ylim)
itext (str) – String to write on plot
small (bool, optional) – fontsize=’small’ if True (default: False)
medium (bool, optional) – fontsize=’medium’ if True (default: False). Medium is taken if no other fontsize is chosen.
large (bool, optional) – fontsize=’large’ if True (default: False)
xlarge (bool, optional) – fontsize=’x-large’ if True (default: False)
xsmall (bool, optional) – fontsize=’x-small’ if True (default: False)
xxlarge (bool, optional) – fontsize=’xx-large’ if True (default: False)
xxsmall (bool, optional) – fontsize=’xx-small’ if True (default: False)
bold (bool, optional) – fontweight=’bold’ if True, else fontsize=’normal’ (default)
italic (bool, optional) – fontstyle=’italic’ if True, else fontstyle=’normal’ (default)
usetex (bool, optional) – Embed into LaTeX math environment if True, else no LaTeX math mode (default)
mathrm (bool, optional) – If True, put text into appropriate LaTeX mathrm/mathit/mathbf environment if usetex==True and italic==True or bold==True. If False, use standard math font if usetex==True (default).
string (bool, optional) – Treat iplot as literal string and not as integer if True (default: False). integer, roman and lower are disabled then.
**kwargs (dict, optional) – All additional parameters are passed passed to
matplotlib.axes.Axes.text()
- Return type:
String on plot
Examples
text2plot(ax, 0.7, 0.6, r'CO$_2$', large=True, usetex=usetex, mathrm=False)