mooonpy.tools.misc_utils module
miscellaneous utilities that do not belong anywhere else
- class mooonpy.tools.misc_utils.ColorMap(name='coolwarm', low=0.0, high=1.0)[source]
Bases:
ListListTableRead csv files of RGB values with a similar format to matplotlib.colormaps. root/tools/lookups contains some example custom colormaps, more can be added by adding files to this directory.
- Currently Supported Colormaps
coolwarm: blue to light to red diverging map (same as matplotlib?)
cooloverwarm: blue to grey to red diverging map
coswan: pink to grey to green diverging map
pyrolyze: green to grey to dark purple diverging map
redblack: red to dark grey linearish map
Read csv files of RGB vales into a ListListTable object.
- mooonpy.tools.misc_utils.auto_colorbar(fig, axs, colormap, step, low=None, high=None, shrink=None, pad=None, label='', orientation='vertical', kwargs=None)[source]
- mooonpy.tools.misc_utils.calculate_axis_ticks(data_min, data_max, ax=None, xaxis=True, tick_range=(5, 9), allowed_spacings=None, raise_error=True)[source]
Calculate optimal axis limits and tick positions.
Parameters
- data_minfloat
Lower limit (usually 0)
- data_maxfloat
Maximum data value to accommodate
- tick_rangetuple of int, optional
(min_ticks, max_ticks), default (5, 9)
- allowed_spacingslist of float, optional
Acceptable tick spacings, default [5, 10, 25, 50, 100, 200, 250]
Returns
- ticksndarray
Array of tick positions
- limitfloat
Upper axis limit
- spacingfloat
Spacing between ticks
Raises
- ValueError
If no valid tick configuration exists
- mooonpy.tools.misc_utils.reset_axis_limits(ax: Axes, x: bool = True, y: bool = True, view: str | None = None, style: str | List[str] | None = None, xtick_spacing: float | None = None, ytick_spacing: float | None = None) None[source]
Reset axis limits based on plotted line data with optional view presets and styling.
Parameters:
- axmatplotlib.axes.Axes
The axes object to modify
- xbool
Tighten x-axis limits to limit of data(default: True)
- ybool
Tighten y-axis limits to limit of data(default: True)
- viewstr, optional
Preset view configurations: - ‘q1’: First quadrant (x_min=0, y_min=0) - ‘q2’: Second quadrant (x_max=0, y_min=0) - ‘q3’: Third quadrant (x_max=0, y_max=0) - ‘q4’: Fourth quadrant (x_min=0, y_max=0) - ‘+x’: Positive x (x_min=0, uses y parameter) - ‘-x’: Negative x (x_max=0, uses y parameter) - ‘+y’: Positive y (y_min=0, uses x parameter) - ‘-y’: Negative y (y_max=0, uses x parameter)
- stylestr or list of str, optional
Styling options: - ‘equal’: Equal aspect ratio (ax.axis(‘equal’)) - ‘square’: Square plot area (ax.axis(‘square’)) - ‘scaled’: Scaled aspect ratio (ax.axis(‘scaled’)) - ‘tight’: Tight layout (ax.axis(‘tight’)) - ‘auto’: Auto scaling (ax.axis(‘auto’)) - ‘off’: Turn off axis (ax.axis(‘off’)) - ‘on’: Turn on axis (ax.axis(‘on’)) - ‘equalticks’: Equal tick spacing with locked aspect ratio - ‘box’: Add box around plot (ax.set_frame_on(True)) - ‘nobox’: Remove box (ax.set_frame_on(False)) - ‘grid’: Add grid (ax.grid(True)) - ‘nogrid’: Remove grid (ax.grid(False)) Can pass a single string or list of strings for multiple styles
- xtick_spacingfloat, optional
Major tick spacing for x-axis (uses MultipleLocator)
- ytick_spacingfloat, optional
Major tick spacing for y-axis (uses MultipleLocator)