Plot.GridLayout

class GridLayout(rows=1, columns=1)

Grid layout that sets up a grid where frames can be placed.

Items are placed at a row, column position and has a size, that is a multiple of rows or columns.

The grid can optionally sync the x- or y-axis of all immediately contained frames.

Parameters:
  • rows (int) – The number of rows.

  • columns (int) – The number of columns.

addItem(item, row=None, column=None, height=1, width=1)

Add item to grid layout.

Parameters:
  • item (LayoutItem based) – The item to add.

  • row (int) – The row to insert at.

  • column (int) – The column to insert at.

  • height (int) – The height (row span).

  • width (int) – The width (column span).

addModel(model, row=None, column=None)

Convenience method for easily adding a plot model to the layout.

Parameters:
  • model (PlotModel) – The plot model to add.

  • row (int) – The row where to add it.

  • column (int) – The column where to add it.

Returns:

The added plot frame.

Return type:

PlotFrame

copy()
Returns:

A copy of the layout.

Return type:

BaseLayout

dimensions()
Returns:

The dimensions (rows, columns).

Return type:

2-tuple of int

find(*, types=None, function=None, **kwargs)

Find plot items within this layout filtered on types and properties.

Find all lines with e.g. the label “Result”, by writing:

layout.find(types=Line, label='Result')

Or find all Scatter plots with an outline:

layout.find(types=Scatter, outline=True).

Or all lines which has a label that starts with the characters ‘band’,:

def labelStartWithBand(item):
    return item.label().lower().startswith('band')

layout.find(
    types=Line,
    function=labelStartsWithBand
).
Parameters:
  • types (None | PlotItem type) – An optional type or multiple types, e.g. Line or Scatter.

  • function (None | function) – An optional filter function taking the plot item as the only input.

  • **kwargs (dict) – Optional properties which should be matched exactly for the items.

Returns:

A list of the items matching the query.

Return type:

list of PlotItem

classmethod fromProperties(properties)

Create a plot storable from a dict of properties.

Used when deserializing a PlotStorable.

Parameters:

properties (dict) – The properties which are used to populate the properties dict of the newly created plot storable.

Returns:

The newly created PlotStorable.

Return type:

PlotStorable

isCompatible(item)

Check compatibility of item.

Parameters:

item (LayoutItem based) – The item.

Returns:

True, if compatible.

Return type:

bool

itemAt(row, column)

Return the frame at the provided position.

Parameters:
  • row (int) – The row where the frame is.

  • column (int) – The column where the frame is.

items()
Returns:

The items in the layout.

Return type:

list of LayoutItems.

mode()
Returns:

The layout mode.

Return type:

enumerator | int

models(plotter=None)

Get all models in the layout for a given plotter.

Parameters:

plotter (Plotter based | NoneType) – The plotter or None for all plotters.

Returns:

The models.

Return type:

list

plotters()
Returns:

The plotters in the layout.

Return type:

set of Plotters

removeItem(item)

Remove item from layout.

Parameters:

item (PlotFrame | BaseLayout) – The item to remove from the layout.

Returns:

True, if removal succeeded. Otherwise False.

Return type:

bool

replaceItem(old_item, new_item)

Replace an existing item.

Parameters:
  • old_item (LayoutItem based) – The old item to replace.

  • new_item (LayoutItem based) – The new item the replaces the old item.

setDimensions(rows, columns)

Set layout dimensions.

Parameters:
  • rows (int) – Number of rows.

  • columns (int) – Number of columns.

setMode(mode)

Set the layout’s mode, i.e. if axes should be shared.

Parameters:

mode (enumerator | int) – The layout type.

setSpacing(spacing)

Set spacing between layout items. This is given as a fraction of the average axis width and height.

Parameters:

spacing (float) – The spacing.

spacing()
Returns:

The spacing between layout items as a fraction sof the average axis width or height.

Return type:

float

Usage Examples

A GridLayout arranges Plot.PlotFrame in a grid. A GridLayout can be constructed in the NanoLab GUI by dropping one plot next to another. See Merge plots for further details.

Below we show how to achieve the same functionality in a script. As an example we construct two PlotModels, the first showing density as a function of distance, the other showing energy as a function of distance. We build a GridLayout showing one model above the other and with their x-axis’es shared.

# Model showing the density as a function of distance.
density_model = Plot.PlotModel(Angstrom, Angstrom**-3)
density_model.addItem(Plot.Line([0, 1,  2] * Angstrom, [0.1, 0.2, 0.3] * Angstrom**-3))

# Frame the model.
density_frame = PlotFrame()
density_frame.addModel(density_model)

# Model showing an energy potential as a function of distance.
potential_model = Plot.PlotModel(Angstrom, eV)
potential_model.addItem(Plot.Line([0, 1, 2] * Angstrom, [2, 3, 4] * eV))

# Frame the model. Position y-axis to the right.
potential_frame = PlotFrame()
potential_frame.addModel(density_model)
potential_frame.title().setVisible(False)

# Construct the GridLayout and add the two models such that they share the x-axis.
# Here we make sure that the bottom frame is twice as high as the first.
layout = Plot.GridLayout(rows=3, columns=1)
layout.setMode(Plot.LAYOUT_MODES.SHARE_X)
layout.addItem(density_frame, row=0, column=0, width=1, height=1)
layout.addItem(potential_frame, row=1, column=0, width=1, height=2)

# Show the plot.
Plot.show(layout)