utils#

Functions that make some features in Matplotlib a bit more convenient.

figure(figsize=1, *args, **kwargs)[source]#

Matplotlib figure but a scalar figsize will multiply rcParams figsize.

Examples

The figure size of the two figures will be equivalent:

plt.rcParams['figure.figsize'] = [6.4, 4.8]
fig1 = figure(2)
fig2 = plt.figure(figsize=(12.8, 9.6))
indexer(arr, index_name=None, axis=0)[source]#

Index an array as part of an interactive function.

For example: iplt.plot(indexor(arr), idx = np.arange(5)).

Parameters:
arrarraylike

The array to be indexed

index_namestr, default: None

The name of the variable the returned function should expect to receive. If None then the function will check for idx, index, ind, and indx.

axisint

which axis to index, default to first axis

Returns:
ffunction

Function to be passed as an argument to an interactive plotting function

nearest_idx(array, value, axis=None)[source]#

Return the index of the array that is closest to value.

Equivalent to np.argmin(np.abs(array-value), axis=axis).

Parameters:
arrayarraylike

The array to search through

valueScalar

The value to search for.

axisint, optional

From np.argmin: “By default, the index is into the flattened array, otherwise along the specified axis.”

Returns:
idxIndexArray

index of array that most closely matches value. If axis=None this will be an integer