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]

Utility function for when you want to index an array as part of an interactive function. For example: iplt.plot(indexor(arr), idx = np.arange(5))

Parameters
  • arr (arraylike) – The array to be indexed

  • index_name (str, 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.

  • axis (int) – which axis to index, default to first axis

Returns

f (function) – 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
  • array (arraylike)

  • value (Scalar)

  • axis (int, optional) – From np.argmin: “By default, the index is into the flattened array, otherwise along the specified axis.”

Returns

idx (IndexArray) – index of array that most closely matches value. If axis=None this will be an integer