class PlotModel(x_unit=<NL.CommonConcepts.PhysicalQuantity.Unit object>, y_unit=<NL.CommonConcepts.PhysicalQuantity.Unit object>, projection='rectilinear')

A plot model contains plot items.

The items contain data objects like lines, bars etc. and can be named for easy retrieval.:

>>> model = PlotModel(x_unit, y_unit)
>>> model.setItem('line', Line([0, 1], [1, 2]))

>>> line = model.item('line').

The plot model also contains the special items: xAxis, yAxis, legend and title. These items are special in the sense that they are only applied when the frame containing the model is reset. So for most purposes they only serve as initial values.

  • x_unit (Unit) – The unit of the x axis of the plot model data.
  • y_unit (Unit) – The unit of the y axis of the plot model data.
  • projection (str) – The projection.

Add a plot item to the model.

Parameters:item (PlotItem based) – The item to add.

Add multiple items to the model.

Parameters:items (list of PlotItem) – The items.
Parameters:name (str) – The name of the axis to get, ‘x’ or ‘y’.
Returns:The x- or y-axis for the sub-plot.
Return type:Axis

Clear all items from the model.

Parameters:plot_item_type (tuple of class) – Optional tuple of item types to clear.

Create a copy of the model (sometimes without items).

Parameters:items (bool) – True, if items should be copied.
Returns:The copied model.
Return type:PlotModel
deleteKey(key, emit=True)

Delete the item stored at specific key.

  • key (str) – The key to delete.
  • emit (bool) – True, if the change should be emitted.
findItems(types=None, function=None, **kwargs)

Find all (possibly nested) items by querying the item properties. Mutliple arguments can be supplied and applies in an exclusive way,:

    function=lambda item: 'line' in item.label(),

It is always faster and safer to find the item directly by traversing the object hierarchy, e.g.:

item = model.item('my_key')

or for nested items:

item = model.item('my_key').items()[1]

If searching for top level items only, the items method can be very useful.

  • types (NoneType | PlotItem class) – An optional type filter specifying the plot items to find e.g. Line or Scatter.
  • function (NoneType | function) – An optional filter function taking the plot item as its only input.
  • **kwargs

    Optional query properties.


The items matching the query.

Return type:


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

Get the item stored on a specific key in the model. Simply returns None if if no item exist at the given key.

Parameters:key (str) – The key to get.
Returns:The item
Return type:object

Get the key for the given item.

Parameters:item (PlotItem) – The given item.
Returns:The key.
Return type:str

All currently set item keys.

Returns:All item keys.
Return type:iterable of str
items(tag=None, plot_item_type=None)

Get plot items of specific type.

  • tag (str) – Filter items on an optional tag.
  • plot_item_type (class | tuple of class) – Filter items on an optional item type.

Returns the items of either plot item type.

Return type:

view | list

Returns:The model legend.
Return type:Legend

Get limits for one axis.

Parameters:name (str) – The axis name.
Return type:tuple of float
Returns:The plotter this model belongs to.
Return type:Plotter | None
Returns:The model projection (‘rectilinear’ or ‘polar’).
Return type:str

Remove an item from the model..

Parameters:item (PlotItem based) – The item to remove.
Returns:The selected plot items.
Return type:list of PlotItems
setItem(key, item, overwrite=True, emit=True)

Add a plot item to the model and assign it to a specific.

  • key (str) – The key to set.
  • item (PlotItem based) – The item to add.
  • overwrite (bool) – True, if any existing item at that key should be silently overwritten.
  • emit (bool) – True, if the addition should be emitted.
setLimits(name=None, lower_limit=None, upper_limit=None, item_filter=None)

Set model data limits. Passing no limits will autoscale the current plot limits.

  • name (str) – The name of the axis (‘x’ or ‘y’).
  • lower_limit (None | float) – The lower limit.
  • upper_limit (None | float) – The upper limit.
  • item_filter (function) – An additional item filter used when automatically setting limits.

Set the model projection.

Parameters:projection (str) – The projection (‘rectilinear’ or ‘polar’).
Returns:The model title.
Return type:Title
static transferUniformProperties(templates, items, exclude_data=True)

Determine which properties that are the same for all of the provided templates, and transfer those properties to the provided items.

  • templates (list of PlotItem) – The list of plot items to use as templates.
  • items (list of PlotItem) – The items to transfer properties to.
  • exclude_data (bool) – True, if we do not wish to transfer the item data.

True, if the transfer succeeded.

Return type:


Returns:The x-axis for the-plot.
Return type:Axis
Returns:The y-axis for the-plot.
Return type:Axis

Usage Examples

The PlotModel is a container for PlotItems like Line, Scatter, Label etc. The most basic PlotModel is constructed without units on the axises:

>>> model = Plot.PlotModel()
>>> model.addItem(Plot.Line([0, 1, 2, 3, 4], [1, 2, 3, 4, 5]))

Set up a PlotModel with Angstrom on the x-axis and eV on the y-axis.

>>> model = PlotModel(x_unit=Angstrom, y_unit=eV)
>>> model.addItem(Line([0, 1, 2, 3, 4] * nm, [1, 2, 3, 4, 5] * eV))

PlotModels can be shown and saved using the and functions.

>>>, 'export.hdf5')


Multiple PlotModels can also be embedded in a common Plot.PlotFrame, and complex plots can be built by combining multiple PlotFrames in a layout like the Plot.GridLayout or the Plot.OverlayLayout.