UI module

User interface.

physicslab.ui.plot_grid(df, plot_value, fig_axs=None, skip=None, title=None, xlabel=None, ylabel=None, row_labels=True, column_labels=True, subplots_adjust_kw=None, **kwargs)[source]

Construct a figure with the same layout as the input.

For example, use it to display SEM images, where rows correspond to different magnifications and columns to samples.
If a df value is None or numpy.nan, skip the individual plot.
To display all figures, call show().
Parameters
  • df (pandas.DataFrame) – Data to drive plotting. E.g. filename to load and plot

  • plot_value (callable) –

    Function to convert a df value into ax.plot.

    def plot_value(ax: matplotlib.axes.Axes, value: object):
        ax.plot(value.x)
        ax.legend()  # Show a legend for each plot.
    

  • fig_axs (tuple(Figure, numpy.ndarray(Axes)), optional) – Figure and axis array to draw to. Axis shape must match that of df. If None, create a new figure, defaults to None

  • skip (list, optional) – Skip df values matching any of the listed items, defaults to None

  • title (str, optional) – Common title. If auto, use df.name if available, defaults to None

  • xlabel (str, optional) – Common x axis label, defaults to None

  • ylabel (str, optional) – Common y axis label, defaults to None

  • row_labels (bool, optional) – Annotate rows by df.index, defaults to True

  • column_labels (bool, optional) – Annotate columns by df.columns, defaults to True

  • subplots_adjust_kw (dict, optional) – Dict with keywords passed to the subplots_adjust() call. E.g. hspace, defaults to None

  • kwargs – All additional keyword arguments are passed to the figure() call. E.g. sharex

Raises

ValueError – If df and axs have different shapes

Returns

Same objects as from matplotlib.pyplot.subplots()

Return type

tuple[Figure, numpy.ndarray[Axes]]