Source code for cytocalc.plotting

import warnings

import matplotlib
import seaborn as sns

from cytocalc import __version__


[docs] def preparePlots(): """ Prepare the plotting environment with consistent styles and settings. This function sets the theme, style, context, and other parameters for matplotlib and seaborn to ensure that all plots have a uniform appearance. """ sns.set_theme() sns.set_style("whitegrid", {"axes.edgecolor": "0"}) sns.set_context("notebook", font_scale=1.5, rc={"lines.linewidth": 1.5}) matplotlib.rcParams["mathtext.fontset"] = "dejavusans" matplotlib.rcParams["figure.dpi"] = 100
[docs] def savefig(*args, **kwargs): """ This function wraps matplotlib's savefig to include Cytocalc version in the saved file. Usage: Identical to matplotlib.pyplot.savefig "read_software_metadata.py" script provides a convenient way to read this metadata back. """ if args[0].endswith(".png"): matplotlib.pyplot.savefig( *args, metadata={"Software": f"Cytocalc {__version__}", **kwargs} ) elif args[0].endswith(".pdf"): matplotlib.pyplot.savefig( *args, metadata={"Creator": f"Cytocalc {__version__}", **kwargs} ) else: warnings.warn( f"\033[93mMetadata about Cytocalc version will not be saved for formats other than pdf and png\033[0m", UserWarning, ) matplotlib.pyplot.savefig(*args, **kwargs)