yieldplotlib.plots.comparison_plots#

Utilities for comparing data across multiple DirectoryNode objects.

This module provides functions for easily comparing data from multiple directory nodes in a single plot or across multiple subplots.

Attributes#

Functions#

_get_plot_method(ax, plot_type)

Get the appropriate plot method for the given plot type.

_calculate_consistent_bins(directories, x[, bins_param])

Calculate consistent histogram bins across multiple directories.

_validate_y_parameter(plot_type, y)

Validate that y parameter is provided when needed.

_handle_histogram(plot_method, directory, x, plot_kwargs)

Handle histogram plotting and legend.

_setup_figure_layout(fig[, suptitle])

Set up figure layout and adjust for suptitle if present.

_create_subplot_titles(directories[, specs])

Create titles for subplots.

_get_data_shape(directory, key)

Get the shape of data for a given key.

_validate_data_shapes(directory, x, y)

Validate that x and y data shapes are compatible for plotting.

_validate_histogram_data(directory, x)

Validate that data is suitable for histogram plotting.

_validate_color_key(directory, c)

Validate that color key data exists and has compatible shape.

_validate_color_data_shapes(directory, x, y, c)

Validate that color data shape is compatible with x and y data.

_plot_data(ax, directory, x, y, plot_type, plot_kwargs)

Plot data using the appropriate method.

compare(ax, directories, x[, y, plot_type, labels, ...])

Plot data from multiple directories on a single axes.

multi(directories, x[, y, plot_type, figsize, ...])

Create a multi-panel figure with one subplot per directory.

panel(directories, *specs[, figsize, suptitle, ...])

Create a multi-panel figure with customizable plotting specifications.

xy_grid(directories, x_keys, y_keys[, plot_type, ...])

Create a grid of plots where each subplot corresponds to a set of (x, y) keys.

Module Contents#

yieldplotlib.plots.comparison_plots.DEFAULT_MARKERS = ['o', 's', '^', 'D', 'v', '<', '>', 'p', '*', 'h', 'H', '+', 'x']#
yieldplotlib.plots.comparison_plots.DEFAULT_LINESTYLES = ['-', '--', '-.', ':']#
yieldplotlib.plots.comparison_plots._get_plot_method(ax, plot_type)[source]#

Get the appropriate plot method for the given plot type.

Args:
ax (matplotlib.axes.Axes):

The axes to get the plot method from.

plot_type (str):

Type of plot to create. Options are ‘scatter’, ‘plot’, or ‘hist’.

Returns:
callable:

The plot method to use.

Raises:
ValueError:

If plot_type is not supported.

yieldplotlib.plots.comparison_plots._calculate_consistent_bins(directories, x, bins_param=None)[source]#

Calculate consistent histogram bins across multiple directories.

Args:
directories (list):

List of DirectoryNode objects.

x (str):

Key for data to calculate bins for.

bins_param (int, sequence, or str, optional):

Bins parameter to use. If None, auto-calculated bins will be used.

Returns:
tuple:

(bins, reference_unit) - bin edges to use and their unit (None if unitless)

yieldplotlib.plots.comparison_plots._validate_y_parameter(plot_type, y)[source]#

Validate that y parameter is provided when needed.

Args:
plot_type (str):

Type of plot to create.

y (str):

Key for y-axis data.

Raises:
ValueError:

If y is required but not provided.

yieldplotlib.plots.comparison_plots._handle_histogram(plot_method, directory, x, plot_kwargs, reference_unit=None)[source]#

Handle histogram plotting and legend.

Args:
plot_method (callable):

The histogram plotting method.

directory (DirectoryNode):

The directory to plot data from.

x (str):

Key for x-axis data.

plot_kwargs (dict):

Keyword arguments for the plot.

reference_unit (astropy.units.Unit, optional):

Reference unit to use for conversion.

Returns:
tuple:

(n, bins, patches) from the histogram.

yieldplotlib.plots.comparison_plots._setup_figure_layout(fig, suptitle=None)[source]#

Set up figure layout and adjust for suptitle if present.

Args:
fig (matplotlib.figure.Figure):

The figure to adjust.

suptitle (str, optional):

Super title for the entire figure.

yieldplotlib.plots.comparison_plots._create_subplot_titles(directories, specs=None)[source]#

Create titles for subplots.

Args:
directories (list):

List of DirectoryNode objects.

specs (list, optional):

List of plot specifications. If provided, creates descriptive titles.

Returns:
list:

List of titles for each subplot.

yieldplotlib.plots.comparison_plots._get_data_shape(directory, key)[source]#

Get the shape of data for a given key.

Args:
directory (DirectoryNode):

The directory to get data from.

key (str):

The key to get data for.

Returns:
tuple:

The shape of the data array.

Raises:
ValueError:

If the key doesn’t exist or the data shape is unexpected.

yieldplotlib.plots.comparison_plots._validate_data_shapes(directory, x, y)[source]#

Validate that x and y data shapes are compatible for plotting.

Args:
directory (DirectoryNode):

The directory to get data from.

x (str):

Key for x-axis data.

y (str):

Key for y-axis data.

Raises:
ValueError:

If the data shapes are incompatible for plotting.

yieldplotlib.plots.comparison_plots._validate_histogram_data(directory, x)[source]#

Validate that data is suitable for histogram plotting.

Args:
directory (DirectoryNode):

The directory to get data from.

x (str):

Key for x-axis data.

Raises:
ValueError:

If the data is not suitable for histogram plotting.

yieldplotlib.plots.comparison_plots._validate_color_key(directory, c)[source]#

Validate that color key data exists and has compatible shape.

Args:
directory (DirectoryNode):

The directory to get data from.

c (str):

Key for color data.

Raises:
ValueError:

If the color key data is invalid.

yieldplotlib.plots.comparison_plots._validate_color_data_shapes(directory, x, y, c)[source]#

Validate that color data shape is compatible with x and y data.

Args:
directory (DirectoryNode):

The directory to get data from.

x (str):

Key for x-axis data.

y (str):

Key for y-axis data.

c (str):

Key for color data.

Raises:
ValueError:

If the data shapes are incompatible.

yieldplotlib.plots.comparison_plots._plot_data(ax, directory, x, y, plot_type, plot_kwargs, reference_unit=None)[source]#

Plot data using the appropriate method.

Args:
ax (matplotlib.axes.Axes):

The axes to plot on.

directory (DirectoryNode):

The directory to plot data from.

x (str):

Key for x-axis data.

y (str):

Key for y-axis data.

plot_type (str):

Type of plot to create.

plot_kwargs (dict):

Keyword arguments for the plot.

reference_unit (astropy.units.Unit, optional):

Reference unit to use for consistent unit conversion.

Returns:

The plot object(s) created.

Raises:
ValueError:

If the data shapes are incompatible for the requested plot type.

yieldplotlib.plots.comparison_plots.compare(ax, directories, x, y=None, plot_type='scatter', labels=None, colors=None, markers=None, linestyles=None, legend=True, **kwargs)[source]#

Plot data from multiple directories on a single axes.

Args:
ax (matplotlib.axes.Axes):

The axes to plot on.

directories (list):

List of DirectoryNode objects to plot.

x (str):

Key for x-axis data.

y (str):

Key for y-axis data.

plot_type (str, optional):

Type of plot to create. Options are ‘scatter’, ‘plot’, or ‘hist’. Default is ‘scatter’.

labels (list, optional):

List of labels for each directory node. If None, uses the directory node class names.

colors (list, optional):

List of colors for each directory. If None, uses default color cycle.

markers (list, optional):

List of markers for scatter plots. If None, uses DEFAULT_MARKERS.

linestyles (list, optional):

List of linestyles for line plots. If None, uses DEFAULT_LINESTYLES.

legend (bool, optional):

Whether to add a legend. Default is True.

**kwargs:

Additional keyword arguments passed to the plot method. Can include ‘c’ for color key data.

Returns:
matplotlib.axes.Axes:

The axes with the plot.

yieldplotlib.plots.comparison_plots.multi(directories, x, y=None, plot_type='scatter', figsize=None, suptitle=None, layout=None, sharex=True, sharey=True, titles=None, **kwargs)[source]#

Create a multi-panel figure with one subplot per directory.

Args:
directories (list):

List of DirectoryNode objects to plot.

x (str):

Key for x-axis data.

y (str, optional):

Key for y-axis data. Not required for histogram plots.

plot_type (str, optional):

Type of plot to create. Options are ‘scatter’, ‘plot’, or ‘hist’. Default is ‘scatter’.

figsize (tuple, optional):

Figure size (width, height) in inches.

suptitle (str, optional):

Super title for the entire figure.

layout (tuple, optional):

Layout for subplots as (rows, cols). If None, will be set automatically.

sharex (bool, optional):

Whether to share the x-axis across subplots. Default is True.

sharey (bool, optional):

Whether to share the y-axis across subplots. Default is True.

titles (list, optional):

List of titles for each subplot. If None, uses directory names.

**kwargs:

Additional keyword arguments passed to the plot method. Can include ‘c’ for color key data, ‘markers’ for scatter plots, ‘linestyles’ for line plots, or ‘colors’ for custom colors for each directory.

Returns:
tuple:

(fig, axes) - The figure and array of axes created.

yieldplotlib.plots.comparison_plots.panel(directories, *specs, figsize=None, suptitle=None, layout=None, sharex=True, sharey=True, titles=None, **kwargs)[source]#

Create a multi-panel figure with customizable plotting specifications.

Args:
directories (list):

List of DirectoryNode objects to plot.

*specs:

Variable number of plot specifications. Each spec is a dictionary with keys: - ‘x’: Key for x-axis data - ‘y’: Key for y-axis data (not required for histograms) - ‘plot_type’: Type of plot (‘scatter’, ‘plot’, ‘hist’) - ‘c’: Key for color data (optional) - Any other kwargs specific to that plot

figsize (tuple, optional):

Figure size (width, height) in inches.

suptitle (str, optional):

Super title for the entire figure.

layout (tuple, optional):

Layout for subplots as (rows, cols). If None, will be determined automatically.

sharex (bool, optional):

Whether to share the x-axis across subplots. Default is True.

sharey (bool, optional):

Whether to share the y-axis across subplots. Default is True.

titles (list, optional):

List of titles for each subplot. If None, uses descriptive titles.

**kwargs:

Additional keyword arguments passed to all plot methods.

Returns:
tuple:

(fig, axes) - The figure and array of axes created.

Example:
fig, axes = ypl.panel(

[exosims, ayo], {‘x’: ‘star_dist’, ‘y’: ‘star_L’, ‘plot_type’: ‘scatter’, ‘c’: ‘star_L’, ‘alpha’: 0.7}, {‘x’: ‘wavelength’, ‘y’: ‘core_thruput’, ‘plot_type’: ‘plot’, ‘lw’: 2}, titles=[‘Star Properties’, ‘Throughput Curve’]

)

yieldplotlib.plots.comparison_plots.xy_grid(directories, x_keys, y_keys, plot_type='scatter', figsize=None, suptitle=None, legend=True, sharex=False, sharey=False, titles=None, **kwargs)[source]#

Create a grid of plots where each subplot corresponds to a set of (x, y) keys.

Each subplot will plot all of the provided DirectoryNode objects using the specified plot type.

Args:
directories (list):

List of DirectoryNode objects.

x_keys (list):

List of keys for x-axis data.

y_keys (list):

List of keys for y-axis data.

plot_type (str, optional):
Type of plot to create. Options are ‘scatter’, ‘plot’, or ‘hist’.

Default is ‘scatter’.

figsize (tuple, optional):

Figure size in inches.

suptitle (str, optional):

Super title for the entire figure.

legend (bool, optional):

Whether to add a legend to each subplot. Default is True.

sharex (bool, optional):

Whether to share the x-axis across subplots. Default is True.

sharey (bool, optional):

Whether to share the y-axis across subplots. Default is True.

titles (list, optional):

List of titles for each subplot. Must have length equal to len(x_keys) * len(y_keys) if provided.

**kwargs:

Additional keyword arguments passed to the plotting method. Can include ‘c’ for color key data.

Returns:
tuple:

(fig, axes) where fig is the matplotlib Figure and axes is a 2D array of Axes.