pcntoolkit.util.plotter ======================= .. py:module:: pcntoolkit.util.plotter .. autoapi-nested-parse:: A module for plotting functions. Functions --------- .. autoapisummary:: pcntoolkit.util.plotter.plot_centiles pcntoolkit.util.plotter.plot_centiles_advanced pcntoolkit.util.plotter.plot_qq pcntoolkit.util.plotter.plot_ridge Module Contents --------------- .. py:function:: plot_centiles(model: pcntoolkit.normative_model.NormativeModel, scatter_data: pcntoolkit.dataio.norm_data.NormData | None = None, centiles: list[float] = [0.05, 0.25, 0.5, 0.75, 0.95], covariate: str | None = None, response_vars: list[str] | None = None, scatter_kwargs: dict = {}, show_figure: bool = True, save_dir: str | None = None) -> list[matplotlib.figure.Figure] Plot the centiles of the model. :param model: The model to plot the centiles for. :type model: :py:class:`NormativeModel` :param scatter_data: The data to scatter on top of the centiles. :type scatter_data: :py:class:`NormData` :param centiles: The centiles to plot. :type centiles: :py:class:`List[float]`, *optional* :param covariate: The covariate to plot on the x-axis. :type covariate: :py:class:`str`, *optional* :param response_vars: The response vars for which to make the plots. All are plotted if this is None, which is default. :type response_vars: :py:class:`List[str] | None` :param scatter_kwargs: Keyword arguments for the scatter plot. May include: - color: The color of the scatter points. Hex code or matplotlib color name. - alpha: The transparency of the scatter points. Between 0 and 1. - s: The size of the scatter points. - marker: The marker of the scatter points. Uses matplotlib marker syntax: https://matplotlib.org/stable/api/markers_api.html - edgecolor: The edge color of the scatter points. Hex code or matplotlib color name. - linewidth: The width of the edge of the scatter points. 0 for no edge. :type scatter_kwargs: :py:class:`dict`, *optional* :param show_figure: If True, call plt.show() after all figures are created. Defaults to True. :type show_figure: :py:class:`bool`, *optional* :param save_dir: Directory to save the figures. Defaults to None. :type save_dir: :py:class:`str | None`, *optional* :returns: One matplotlib Figure per response variable. :rtype: :py:class:`list[Figure]` .. py:function:: plot_centiles_advanced(model: pcntoolkit.normative_model.NormativeModel, centiles: list[float] | numpy.ndarray | None = None, conditionals: list[float] | numpy.ndarray | None = None, covariate: str | None = None, covariate_ranges: dict[str, tuple[float, float]] | None = None, response_vars: list[str] | None = None, batch_effects: dict[str, list[str]] | None | Literal['all'] = None, scatter_data: pcntoolkit.dataio.norm_data.NormData | None = None, harmonize_data: bool = True, hue_data: str = 'site', markers_data: str = 'sex', show_other_data: bool = False, show_thrivelines: bool = False, z_thrive: float = 0.0, show_figure: bool = True, save_dir: str | None = None, show_centile_labels: bool = True, show_legend: bool = True, show_yhat: bool = False, plt_kwargs: dict | None = None, **kwargs: Any) -> list[matplotlib.figure.Figure] Generate centile plots for response variables with optional data overlay. This function creates visualization of centile curves for all response variables in the dataset. It can optionally show the actual data points overlaid on the centile curves, with customizable styling based on categorical variables. :param model: The model to plot the centiles for. :type model: :py:class:`NormativeModel` :param centiles: The centiles to plot. If None, the default centiles will be used. :type centiles: :py:class:`List[float] | np.ndarray | None`, *optional* :param conditionals: A list of x-coordinates for which to plot the conditionals :type conditionals: :py:class:`List[float] | np.ndarray | None`, *optional* :param covariate: The covariate to plot on the x-axis. If None, the first covariate in the model will be used. :type covariate: :py:class:`str | None`, *optional* :param covariate_ranges: The range of the covariate to plot on the x-axis. If None, the range of the covariate that was in the train data will be used. :type covariate_ranges: :py:class:`tuple[float`, :py:class:`float]`, *optional* :param response_vars: The response vars for which to make the plots. All are plotted if this is None, which is default. :type response_vars: :py:class:`List[str] | None` :param batch_effects: The batch effects to plot the centiles for. If None, the batch effect that appears first in alphabetical order will be used. :type batch_effects: :py:class:`Dict[str`, :py:class:`List[str]] | None | Literal[```"all"``:py:class:`]`, *optional* :param scatter_data: Data to scatter on top of the centiles. :type scatter_data: :py:class:`NormData | None`, *optional* :param harmonize_data: Whether to harmonize the scatter data before plotting. Data will be harmonized to the batch effect for which the centiles were computed. :type harmonize_data: :py:class:`bool`, *optional* :param hue_data: The column to use for color coding the data. If None, the data will not be color coded. :type hue_data: :py:class:`str`, *optional* :param markers_data: The column to use for marker styling the data. If None, the data will not be marker styled. :type markers_data: :py:class:`str`, *optional* :param show_other_data: Whether to scatter data belonging to groups not in batch_effects. :type show_other_data: :py:class:`bool`, *optional* :param show_figure: If True, call plt.show() after all figures are created. Defaults to True. :type show_figure: :py:class:`bool`, *optional* :param save_dir: The directory to save the plot to. If None, the plot will not be saved. :type save_dir: :py:class:`str | None`, *optional* :param show_centile_labels: Whether to show the centile labels on the plot. :type show_centile_labels: :py:class:`bool`, *optional* :param show_legend: Whether to show the legend on the plot. :type show_legend: :py:class:`bool`, *optional* :param plt_kwargs: Additional keyword arguments passed to plt.subplots(). :type plt_kwargs: :py:class:`dict`, *optional* :param \*\*kwargs: Additional keyword arguments for the model.compute_centiles method. :type \*\*kwargs: :py:class:`Any`, *optional* :returns: One matplotlib Figure per response variable. :rtype: :py:class:`list[Figure]` .. py:function:: plot_qq(data: pcntoolkit.dataio.norm_data.NormData, plt_kwargs: dict | None = None, bound: int | float = 0, plot_id_line: bool = False, hue_data: str | None = None, markers_data: str | None = None, split_data: str | None = None, response_vars: list[str] | None = None, seed: int = 42, show_figure: bool = True, save_dir: str | None = None) -> list[matplotlib.figure.Figure] Plot QQ plots for each response variable in the data. :param data: Data containing the response variables. :type data: :py:class:`NormData` :param plt_kwargs: Additional keyword arguments for the plot. Defaults to None. :type plt_kwargs: :py:class:`dict` or :py:obj:`None`, *optional* :param bound: Axis limits for the plot. Defaults to 0. :type bound: :py:class:`int` or :py:class:`float`, *optional* :param plot_id_line: Whether to plot the identity line. Defaults to False. :type plot_id_line: :py:class:`bool`, *optional* :param hue_data: Column to use for coloring. Defaults to None. :type hue_data: :py:class:`str` or :py:obj:`None`, *optional* :param markers_data: Column to use for marker styling. Defaults to None. :type markers_data: :py:class:`str` or :py:obj:`None`, *optional* :param split_data: Column to use for splitting data. Defaults to None. :type split_data: :py:class:`str` or :py:obj:`None`, *optional* :param response_vars: The response vars for which to make the plots. All are plotted if this is None, which is default. :type response_vars: :py:class:`List[str] | None = None,` :param seed: Random seed for reproducibility. Defaults to 42. :type seed: :py:class:`int`, *optional* :param show_figure: If True, call plt.show() after all figures are created. Defaults to True. :type show_figure: :py:class:`bool`, *optional* :returns: One matplotlib Figure per response variable. :rtype: :py:class:`list[Figure]` .. rubric:: Examples >>> plot_qq(data, plt_kwargs={"figsize": (10, 6)}, bound=3) .. py:function:: plot_ridge(data: pcntoolkit.dataio.norm_data.NormData, variable: Literal['Z', 'Y'], split_by: str, response_vars: list[str] | None = None, show_figure: bool = True, save_dir: str | None = None, **kwargs: Any) -> list[matplotlib.figure.Figure] Plot a ridge plot for each response variable in the data. Creates a density plot for the variable split by the split_by variable. Each density plot will be on a different row. The hue of the density plot will be the split_by variable. :param data: Data containing the response variable. :type data: :py:class:`NormData` :param variable: The variable to plot on the x-axis. (Z or Y) :type variable: :py:class:`Literal[```"Z"``, ``"Y"``:py:class:`]` :param split_by: The variable to split the data by. :type split_by: :py:class:`str` :param response_vars: The response vars for which to make the plots. All are plotted if this is None, which is default. :type response_vars: :py:class:`list[str]` or :py:obj:`None`, *optional* :param show_figure: If True, call plt.show() after all figures are created. Defaults to True. :type show_figure: :py:class:`bool`, *optional* :param save_dir: The directory to save the plot to. Defaults to None. :type save_dir: :py:class:`str` or :py:obj:`None`, *optional* :param \*\*kwargs: Additional keyword arguments for the plot. :type \*\*kwargs: :py:class:`Any`, *optional* :returns: One matplotlib Figure per response variable. :rtype: :py:class:`list[Figure]`