NanoLab Plot Reference Manual

The Plot module is built with the aim of making it easy to create publication quality scientific plots.

All plots can be saved using Plot.save and loaded using nlread. Specific plot items can be found using the Plot.Plot find method. An interactive plot window can be launched with the Plot.show function.

The NanoLab Plot framework helps you to edit, show and save plots created by the Analyzers in NanoLab. The Plot framework also makes it straight-forward to construct simple or complex plots from scratch, and to mix and match those plots with the plots created in NanoLab.

Note

All parts of the Plot framework are contained within the Plot module, meaning that all relevant classes and functions must be called with the Plot prefix.

Modifying Plots

Any plot constructed through the NanoLab GUI can be saved to an HDF5 file in the save dialog. The plots will show up in the NanoLab and can be opened again by the PlotViewer Plugin.

In a script the saved plot can be loaded by using the standard nlread function:

>>> plot = nlread('saved_plot.hdf5')[0]

The plot can then be shown using the special Plot.show function:

>>> Plot.show(plot, size=(600, 400))

This will show the plot in an interactive plot window with the full editing capability of NanoLab. The modified plot can then again be saved in the plot window; or it can be saved through scripting by using the special Plot.save function.

The plot can also be modified in a script. The easiest way to find the relevant plot items is through the Plot.Plot.find method:

>>> oxygen_lines = plot.find(types=Plot.Line, label='Oxygen')

Building Plots

All plots are constructed from a Plot.PlotModel.

>>> model = Plot.PlotModel()

The plots are then built from plot items, such as Plot.Line, Plot.Scatter, Plot.HorizontalFill, Plot.Arrow, Plot.Measure, etc.:

>>> model.addItem(
>>>    Line([0, 1, 2, 3, 4], [1, 2.2, 3.4, 6.7, 8.9])
>>>)

Multiple PlotModels can then be embedded in a Plot.GridLayout or Plot.OverlayLayout in order to build complex plots.

When a plot has been constructed it can be shown using the Plot.show function and saved using the Plot.save function.

Let us try to sketch a complete example that shows how to plot a dashed red Plot.Line with star markers on a log-plot. We also add a Plot.CurveFit to the line data.

# PlotModel with custom units.
model = Plot.PlotModel(x_unit=Angstrom, y_unit=eV)

# Change title
model.framing().setTitle('My plot')

# Set axis label and scale
model.xAxis().setLabel('Length')
model.yAxis().setLabel('Energy')
model.yAxis().setScale(Plot.SCALES.LOG)

# Show legend.
model.legend().setVisible(True)

#Line.
line = Plot.Line([1, 2, 3, 4, 4] * nm, [1, 2.2, 3, 2.2, 1] * eV)
line.setLabel('My red line')
line.setColor('red')
line.setLineStyle(Plot.LINE_STYLES.DASHED)
line.setMarkerStyle(Plot.MARKER_STYLES.STAR)
line.setMarkerSize(8)

# Add fit.
fit = Plot.CurveFit('a * (x - x0)**2 + b')
line.addItem(fit)

# Add line.
model.addItem(line)

# Auto-adjust axis limits.
model.setLimits()

# Show plot and save afterwards to file and as raster.
Plot.show(model)
Plot.save(model, 'my_plot.hdf5')
Plot.save(model, 'my_plot.png')

Later, the plot can be loaded, and the line color can be changed to e.g. blue before it is saved again.

Framework

These are the core parts of the framework.

Plot Items

These are all the different items that can be added to or edited in a PlotModel.

Plot Layouts

These are the classes used for laying out plots in complex layouts.

Plot Constants

Some of the plot options must be supplied as special constants. All constants enumerations are uppercase, and their options are accessed using the usual dot notation, e.g. Plot.COLOR_MODES.COLOR or Plot.SCALES.LOG.

Enum

Constants

Plot.ALIGNMENTS

  • TOP

  • CENTER

  • BOTTOM

  • LEFT

  • RIGHT

Plot.ARROW_STYLES

  • FILLED

  • UNFILLED

  • NONE

Plot.BOUNDARY_CONDITIONS

  • EXCLUDE

  • PERIODIC

  • MIRROR

  • REFLECT

Plot.COLOR_MODES

  • COLOR

  • COLORS

  • MANY_COLORS

  • COLOR_MAP

Plot.DETAIL_LEVELS

  • BASIC

  • MEDIUM

  • FULL

Plot.EDGES

  • LEFT

  • RIGHT

  • TOP

  • BOTTOM

  • CENTER

Plot.KERNELS

  • AVERAGE

  • GAUSSIAN

Plot.LAYOUT_MODES

  • NORMAL

  • SHARE_X

  • SHARE_Y

  • SHARE_BOTH

Plot.LEGEND_LOCATIONS

  • BEST

  • UPPER_LEFT

  • UPPER_CENTER

  • UPPER_RIGHT

  • CENTER_LEFT

  • CENTER

  • CENTER_RIGHT

  • LOWER_LEFT

  • LOWER_CENTER

  • LOWER_RIGHT

  • RIGHT

Plot.LINE_STYLES

  • SOLID

  • DASHED

  • DASHDOT

  • DOTTED

  • NONE

Plot.MARKER_STYLES

  • NONE

  • POINT

  • PIXEL

  • CIRCLE

  • TRIANGLE_DOWN

  • TRIANGLE_UP

  • TRIANGLE_LEFT

  • TRIANGLE_RIGHT

  • TRISTAR_DOWN

  • TRISTAR_UP

  • TRISTAR_LEFT

  • TRISTAR_RIGHT

  • OCTAGON

  • SQUARE

  • PENTAGON

  • PLUS

  • STAR

  • HEXAGON1

  • HEXAGON2

  • CROSS

  • DIAMOND

  • THIN_DIAMOND

  • VERTICAL_LINE

  • HORIZONTAL_LINE

Plot.OWNERS

  • MODEL

  • VIEW

Plot.MEASURE_LABEL_POSITIONS

  • INSIDE

  • OUTSIDE

Plot.PROJECTIONS

  • RECTILINEAR

  • POLAR

Plot.SCALES

  • LINEAR

  • LOG

  • SYMLOG

  • SQUARE

Plot.TICK_DIRECTIONS

  • OUT

  • IN

  • BOTH

Full Plot module

All the plot classes and functions in alphabetical order: