yieldplotlib.util#

Utility functions.

Functions#

get_nice_number(value[, round])

Calculates a "nice" number for labeling axes in a plot.

calculate_axis_limits_and_ticks(data_min, data_max[, ...])

Calculates the axis limits and tick spacing for a plot.

is_monotonic(x)

Checks if an array is monotonic.

rgetattr(obj, attr, *args)

Recursively get attributes of an object.

discretize_colormap(num_colors, colormap_name[, ...])

Returns evenly spaced discrete colors from a matplotlib colormap.

find_unit_for_module_key(module_key, module_name, key_map)

Find the unit for a given module-specific key.

get_unit(key, module_name[, find_unit_func])

Get the associated unit for a given key.

Module Contents#

yieldplotlib.util.get_nice_number(value, round=False)[source]#

Calculates a “nice” number for labeling axes in a plot.

Args:
value (float):

The value to be transformed into a “nice” number.

round (bool, optional):

If True, rounds the number to the nearest “nice” number. If False, the number is only scaled to be a “nice” number.

Returns:
float:

A “nice” number that is a rounded or scaled version of the input value.

yieldplotlib.util.calculate_axis_limits_and_ticks(data_min, data_max, num_ticks=5, exact=False)[source]#

Calculates the axis limits and tick spacing for a plot.

Args:
data_min (float):

The minimum value of the data.

data_max (float):

The maximum value of the data.

num_ticks (int, optional):

The desired number of tick marks on the axis. Default is 5.

exact (bool, optional):

If True, use exact min and max values for the limits. If False, the limits are adjusted to “nice” values.

Returns:
tuple:
nice_min (float):

The adjusted minimum axis limit.

nice_max (float):

The adjusted maximum axis limit.

tick_spacing (float):

The spacing between ticks.

offset (float):

A small offset to apply to the axis limits for better visualization.

yieldplotlib.util.is_monotonic(x)[source]#

Checks if an array is monotonic.

yieldplotlib.util.rgetattr(obj, attr, *args)[source]#

Recursively get attributes of an object.

yieldplotlib.util.discretize_colormap(num_colors, colormap_name, start_frac=0.1, end_frac=0.9)[source]#

Returns evenly spaced discrete colors from a matplotlib colormap.

yieldplotlib.util.find_unit_for_module_key(module_key, module_name, key_map)[source]#

Find the unit for a given module-specific key.

Searches through the KEY_MAP to find a mapping where the provided module key matches the ‘name’ field for the specified module. If found, returns the corresponding unit.

Args:
module_key (str):

The module-specific key (e.g., ‘Angdiam (mas)’ for AYO, ‘pixelScale’ for EXOSIMS).

module_name (str):

The name of the module (e.g., ‘AYOCSVFile’, ‘EXOSIMSInputFile’).

key_map (dict):

The key mapping dictionary to use for lookups.

Returns:
str or None:

The unit string if found, None otherwise.

yieldplotlib.util.get_unit(key, module_name, find_unit_func=None)[source]#

Get the associated unit for a given key.

This generic method handles both yieldplotlib keys and module-specific keys: 1. First tries a direct lookup in KEY_MAP (assuming key is a yieldplotlib key) 2. If not found, tries to find the corresponding yieldplotlib key by looking up

the module-specific key in KEY_MAP

Args:
key (str):

The key to look up the unit for (can be either a yieldplotlib key or a module-specific key).

module_name (str):

The name of the module making the request (used for KEY_MAP lookup).

find_unit_func (callable, optional):

Optional custom fallback function that takes a key and returns a unit string. If None, the built-in find_unit_for_module_key function will be used.

Returns:
astropy.units.Unit or None:

The astropy Unit object if found, None otherwise.