uclchem.style#
Publication-quality matplotlib style for UCLCHEM.
Applies STIX serif fonts and MNRAS-compatible sizes without requiring a
LaTeX installation. The style is applied automatically when uclchem is
imported. Set the environment variable UCLCHEM_NO_STYLE=1 before
importing to suppress auto-apply.
Key Functions:
apply()- Apply the UCLCHEM rcParams globallyreset()- Restore matplotlib defaultscontext()- Temporary style context managerformat_chemical_formula()- Convert species names to mathtext labelsformat_reaction_label()- Convert reaction strings to mathtext labels
Example Usage:
>>> import uclchem # style applied on import
>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots()
>>> _ = ax.set_xlabel(uclchem.style.format_chemical_formula("HCO+"))
>>> uclchem.style.reset() # restore matplotlib defaults
>>> uclchem.style.apply() # re-apply UCLCHEM style
Module Contents#
Functions#
|
Apply style to the global matplotlib rcParams. |
|
Apply style temporarily as a context manager. |
|
Convert a UCLCHEM species name to a mathtext label. |
|
Convert a UCLCHEM reaction string to a mathtext legend label. |
|
Restore matplotlib's built-in default rcParams. |
Attributes#
- uclchem.style.apply(style: dict[str, object] = UCLCHEM_STYLE) None[source]#
Apply style to the global matplotlib rcParams.
- Parameters:
style (dict[str, object]) – Mapping of rcParam keys to values. Defaults to
UCLCHEM_STYLE.
- uclchem.style.context(style: dict[str, object] = UCLCHEM_STYLE) collections.abc.Generator[None, None, None][source]#
Apply style temporarily as a context manager.
- Parameters:
style (dict[str, object]) – Mapping of rcParam keys to values. Defaults to
UCLCHEM_STYLE.- Yields:
None – All
pltcalls inside the block use style; settings are restored on exit.
Examples
>>> import uclchem >>> with uclchem.style.context(): ... pass # plots here use UCLCHEM style
- uclchem.style.format_chemical_formula(name: str) str[source]#
Convert a UCLCHEM species name to a mathtext label.
Subscripts digit runs and superscripts charge suffixes so the result renders correctly with matplotlib’s built-in mathtext engine (no LaTeX required).
- Parameters:
name (str) – UCLCHEM species name, e.g.
"HCO+","#H2O","@CO2","E-","o-H2".- Returns:
Mathtext string, e.g.
r"$\mathrm{HCO^{+}}$".- Return type:
Examples
>>> format_chemical_formula("HCO+") '$\\mathrm{HCO^{+}}$' >>> format_chemical_formula("H2O") '$\\mathrm{H_{2}O}$' >>> format_chemical_formula("#H2O") '#$\\mathrm{H_{2}O}$'
- uclchem.style.format_reaction_label(rxn: str, k_mean: float | None = None) str[source]#
Convert a UCLCHEM reaction string to a mathtext legend label.
- Parameters:
- Returns:
Mathtext string suitable for use as a matplotlib legend label.
- Return type:
Examples
>>> format_reaction_label("H2 + O -> OH + H") '$\\mathrm{H_{2}}$ + $\\mathrm{O}$ $\\rightarrow$ $\\mathrm{OH}$ + $\\mathrm{H}$'