defdap.plotting module

class defdap.plotting.Plot(ax=None, axParams={}, fig=None, makeInteractive=False, title=None, **kwargs)[source]

Bases: object

Class used for creating and manipulating plots.

checkInteractive()[source]

Checks if current plot is interactive.

Raises:

Exception – If plot is not interactive

addEventHandler(eventName, eventHandler)[source]
addAxes(loc, proj='2d')[source]

Add axis to current plot

Parameters:
  • loc – Location of axis.

  • proj (str, {2d, 3d}) – 2D or 3D projection.

Return type:

matplotlib.Axes.axes

addButton(label, clickHandler, loc=(0.8, 0.0, 0.1, 0.07), **kwargs)[source]

Add a button to the plot.

Parameters:
  • label (str) – Label for the button.

  • clickHandler – Click handler to assign.

  • loc (list(float), len 4) – Left, bottom, width, height.

  • kwargs – All other arguments passed to matplotlib.widgets.Button.

addTextBox(label, submitHandler=None, changeHandler=None, loc=(0.8, 0.0, 0.1, 0.07), **kwargs)[source]

Add a text box to the plot.

Parameters:
  • label (str) – Label for the button.

  • submitHandler – Submit handler to assign.

  • loc (list(float), len 4) – Left, bottom, width, height.

  • kwargs – All other arguments passed to matplotlib.widgets.TextBox.

Return type:

matplotlotlib.widgets.TextBox

addText(ax, x, y, txt, **kwargs)[source]

Add text to the plot.

Parameters:
addArrow(startEnd, persistent=False, clearPrev=True, label=None)[source]

Add arrow to grain plot.

Parameters:
  • startEnd (4-tuple) – Starting (x, y), Ending (x, y).

  • persistent – If persistent, do not clear arrow with clearPrev.

  • clearPrev – Clear all non-persistent arrows.

  • label – Label to place near arrow.

setSize(size)[source]

Set size of plot.

Parameters:

size (float, float) – Width and height in inches.

setTitle(txt)[source]

Set title of plot.

Parameters:

txt (str) – Title to set.

lineSlice(event, plot, action=None)[source]

Catch click and drag then draw an arrow.

Parameters:
  • event – Click event.

  • plot (defdap.plotting.Plot) – Plot to capture clicks from.

  • action – Further action to perform.

Examples

To use, add a click and release event handler to your plot, pointing to this function:

>>> plot.addEventHandler('button_press_event',lambda e, p: lineSlice(e, p))
>>> plot.addEventHandler('button_release_event', lambda e, p: lineSlice(e, p))
property exists
clear()[source]

Clear plot.

draw()[source]

Draw plot

class defdap.plotting.MapPlot(callingMap, fig=None, ax=None, axParams={}, makeInteractive=False, **kwargs)[source]

Bases: Plot

Class for creating a map plot.

addMap(mapData, vmin=None, vmax=None, cmap='viridis', **kwargs)[source]

Add a map to a plot.

Parameters:
Return type:

matplotlib.image.AxesImage

addColourBar(label, layer=0, **kwargs)[source]

Add a colour bar to plot.

Parameters:
addScaleBar(scale=None)[source]

Add scale bar to plot.

Parameters:

scale (float) – Size of a pixel in microns.

addGrainBoundaries(kind='pixel', boundaries=None, colour=None, dilate=False, draw=True, **kwargs)[source]

Add grain boundaries to the plot.

Parameters:
  • kind (str, {"pixel", "line"}) – Type of boundaries to plot, either a boundary image or a collection of line segments.

  • boundaries (various, optional) – Boundaries to plot, either a boundary image or a list of pairs of coordinates representing the start and end of each boundary segment. If not provided the boundaries are loaded from the calling map.

  • colour (various) –

    One of:
    • Colour of all boundaries as a string (only option pixel kind)

    • Colour of all boundaries as RGBA tuple

    • List of values to represent colour of each line relative to a norm and cmap

  • dilate (bool) – If true, dilate the grain boundaries.

  • kwargs – If line kind then other arguments are passed to matplotlib.collections.LineCollection().

Returns:

matplotlib.image.AxesImage if type is pixel

Return type:

Various

addGrainHighlights(grainIds, grainColours=None, alpha=None, newLayer=False)[source]

Highlight grains in the plot.

Parameters:
  • grainIds (list) – List of grain IDs to highlight.

  • grainColours – Colour to use for grain highlight.

  • alpha (float) – Alpha (transparency) to use for grain highlight.

  • newLayer (bool) – If true, make a new layer in imgLayers.

Return type:

matplotlib.image.AxesImage

addGrainNumbers(fontsize=10, **kwargs)[source]

Add grain numbers to a map.

Parameters:
addLegend(values, labels, layer=0, **kwargs)[source]

Add a legend to a map.

Parameters:
  • values (list) – Values to find colour patched for.

  • labels (list) – Labels to assign to values.

  • layer (int) – Image layer to generate legend for.

  • kwargs – Pass other arguments to matplotlib.pyplot.legend().

addPoints(x, y, updateLayer=None, **kwargs)[source]

Add points to plot.

Parameters:
classmethod create(callingMap, mapData, fig=None, figParams={}, ax=None, axParams={}, plot=None, makeInteractive=False, plotColourBar=False, vmin=None, vmax=None, cmap=None, clabel='', plotGBs=False, dilateBoundaries=False, boundaryColour=None, plotScaleBar=False, scale=None, highlightGrains=None, highlightColours=None, highlightAlpha=None, **kwargs)[source]

Create a plot for a map.

Parameters:
  • callingMap (base.Map) – DIC or EBSD map which called this plot.

  • mapData (numpy.ndarray) – Data to be plotted.

  • fig (matplotlib.figure.Figure) – Matplotlib figure to plot on.

  • figParams – Passed to defdap.plotting.Plot.

  • ax (matplotlib.axes.Axes) – Matplotlib axis to plot on.

  • axParams – Passed to defdap.plotting.Plot as axParams.

  • plot (defdap.plotting.Plot) – If none, use current plot.

  • makeInteractive – If true, make plot interactive

  • plotColourBar (bool) – If true, plot a colour bar next to the map.

  • vmin (float, optional) – Minimum value for the colour scale.

  • vmax (float, optional) – Maximum value for the colour scale.

  • cmap (str) – Colour map.

  • clabel (str) – Label for the colour bar.

  • plotGBs (bool) – If true, plot the grain boundaries on the map.

  • dilateBoundaries (bool) – If true, dilate the grain boundaries.

  • boundaryColour (str) – Colour to use for the grain boundaries.

  • plotScaleBar (bool) – If true, plot a scale bar in the map.

  • scale (float) – Size of pizel in microns.

  • highlightGrains (list(int)) – List of grain IDs to highlight.

  • highlightColours (str) – Colour to hightlight grains.

  • highlightAlpha (float) – Alpha (transparency) by which to highlight grains.

  • kwargs – All other arguments passed to defdap.plotting.MapPlot.addMap()

Return type:

defdap.plotting.MapPlot

class defdap.plotting.GrainPlot(callingGrain, fig=None, ax=None, axParams={}, makeInteractive=False, **kwargs)[source]

Bases: Plot

Class for creating a map for a grain.

addMap(mapData, vmin=None, vmax=None, cmap='viridis', **kwargs)[source]

Add a map to a grain plot.

Parameters:
  • mapData (numpy.ndarray) – Grain data to plot

  • vmin (float) – Minimum value for the colour scale.

  • vmax (float) – Maximum value for the colour scale.

  • cmap – Colour map to use.

  • kwargs – Other arguments are passed to matplotlib.pyplot.imshow().

Return type:

matplotlib.image.AxesImage

addColourBar(label, layer=0, **kwargs)[source]

Add colour bar to grain plot.

Parameters:
addScaleBar(scale=None)[source]

Add scale bar to grain plot.

Parameters:

scale (float) – Size of pixel in micron.

addTraces(angles, colours, topOnly=False, pos=None, **kwargs)[source]

Add slip trace angles to grain plot. Illustrated by lines crossing through central pivot point to create a circle.

Parameters:
  • angles (list) – Angles of slip traces.

  • colours (list) – Colours to plot.

  • topOnly (bool, optional) – If true, plot only a semi-circle instead of a circle.

  • pos (tuple) – Position of slip traces.

  • kwargs – Other arguments are passed to matplotlib.pyplot.quiver()

addSlipTraces(topOnly=False, colours=None, pos=None, **kwargs)[source]

Add slip traces to plot, based on the calling grain’s slip systems.

Parameters:
  • colours (list) – Colours to plot.

  • topOnly (bool, optional) – If true, plot only a semi-circle instead of a circle.

  • pos (tuple) – Position of slip traces.

  • kwargs – Other arguments are passed to matplotlib.pyplot.quiver()

addSlipBands(topOnly=False, grainMapData=None, angles=None, pos=None, thres=None, min_dist=None, **kwargs)[source]

Add lines representing slip bands detected by Radon transform in calcSlipBands().

Parameters:
classmethod create(callingGrain, mapData, fig=None, figParams={}, ax=None, axParams={}, plot=None, makeInteractive=False, plotColourBar=False, vmin=None, vmax=None, cmap=None, clabel='', plotScaleBar=False, scale=None, plotSlipTraces=False, plotSlipBands=False, **kwargs)[source]

Create grain plot.

Parameters:
  • callingGrain (base.Grain) – DIC or EBSD grain which called this plot.

  • mapData – Data to be plotted.

  • fig (matplotlib.figure.Figure) – Matplotlib figure to plot on.

  • figParams – Passed to defdap.plotting.Plot.

  • ax (matplotlib.axes.Axes) – Matplotlib axis to plot on.

  • axParams – Passed to defdap.plotting.Plot as axParams.

  • plot (defdap.plotting.Plot) – If none, use current plot.

  • makeInteractive – If true, make plot interactive

  • plotColourBar (bool) – If true, plot a colour bar next to the map.

  • vmin (float) – Minimum value for the colour scale.

  • vmax (float) – Maximum value for the colour scale.

  • cmap – Colour map.

  • clabel (str) – Label for the colour bar.

  • plotScaleBar (bool) – If true, plot a scale bar in the map.

  • scale (float) – Size of pizel in microns.

  • plotSlipTraces (bool) – If true, plot slip traces with addSlipTraces()

  • plotSlipBands (bool) – If true, plot slip traces with addSlipBands()

  • kwargs – All other arguments passed to defdap.plotting.GrainPlot.addMap()

Return type:

defdap.plotting.GrainPlot

class defdap.plotting.PolePlot(plotType, crystalSym, projection=None, fig=None, ax=None, axParams={}, makeInteractive=False, **kwargs)[source]

Bases: Plot

Class for creating an inverse pole figure plot.

addAxis()[source]

Draw axes on the IPF based on crystal symmetry.

Raises:

NotImplementedError – If a crystal type other than ‘cubic’ or ‘hexagonal’ are selected.

addLine(startPoint, endPoint, plotSyms=False, res=100, **kwargs)[source]

Draw lines on the IPF plot.

Parameters:
  • startPoint (numpy.ndarray) – Start point in crystal coordinates (i.e. [0,0,1]).

  • endPoint (numpy.ndarray) – End point in crystal coordinates, (i.e. [1,0,0]).

  • plotSyms (bool, optional) – If true, plot all symmetrically equivelant points.

  • res (int) – Number of points within each line to plot.

  • kwargs – All other arguments are passed to matplotlib.pyplot.plot().

labelPoint(point, label, padX=0, padY=0, **kwargs)[source]

Place a label near a coordinate in the pole plot.

Parameters:
  • point (tuple) – (x, y) coordinate to place text.

  • label (str) – Text to use in label.

  • padX (int, optional) – Pad added to x coordinate.

  • padY (int, optional) – Pad added to y coordinate.

  • kwargs – Other arguments are passed to matplotlib.axes.Axes.text().

addPoints(alphaAng, betaAng, markerColour=None, markerSize=None, **kwargs)[source]

Add a point to the pole plot.

Parameters:
  • alphaAng – Inclination angle to plot.

  • betaAng – Azimuthal angle (around z axis from x in anticlockwise as per ISO) to plot.

  • markerColour (str or list(str), optional) – Colour of marker. If two specified, then the point will have two semicircles of different colour.

  • markerSize (float) – Size of marker.

  • kwargs – Other arguments are passed to matplotlib.axes.Axes.scatter().

Raises:

Exception – If more than two colours are specified

addColourBar(label, layer=0, **kwargs)[source]

Add a colour bar to the pole plot.

Parameters:
  • label (str) – Label to place next to colour bar.

  • layer (int) – Layer number to add the colour bar to.

  • kwargs – Other argument are passed to matplotlib.pyplot.colorbar().

addLegend(label='Grain area (μm$^2$)', number=6, layer=0, scaling=1, **kwargs)[source]

Add a marker size legend to the pole plot.

Parameters:
  • label (str) – Label to place next to legend.

  • number – Number of markers to plot in legend.

  • layer (int) – Layer number to add the colour bar to.

  • scaling (float) – Scaling applied to the data.

  • kwargs – Other argument are passed to matplotlib.pyplot.legend().

static stereoProject(*args)[source]

Stereographic projection of pole direction or pair of polar angles.

Parameters:

args (numpy.ndarray, len 2 or 3) – 2 arguments for polar angles or 3 arguments for pole directions.

Returns:

x coordinate, y coordinate

Return type:

float, float

Raises:

Exception – If input array has incorrect length

static lambertProject(*args)[source]

Lambert Projection of pole direction or pair of polar angles.

Parameters:

args (numpy.ndarray, len 2 or 3) – 2 arguments for polar angles or 3 arguments for pole directions.

Returns:

x coordinate, y coordinate

Return type:

float, float

Raises:

Exception – If input array has incorrect length

class defdap.plotting.HistPlot(plotType='scatter', axesType='linear', density=True, fig=None, ax=None, axParams={}, makeInteractive=False, **kwargs)[source]

Bases: Plot

Class for creating a histogram.

addHist(histData, bins=100, range=None, line='o', label=None, **kwargs)[source]

Add a histogram to the current plot

Parameters:
  • histData (numpy.ndarray) – Data to be used in the histogram.

  • bins (int) – Number of bins to use for histogram.

  • range (tuple or None, optional) – The lower and upper range of the bins

  • line (str, optional) – Marker or line type to be used.

  • label (str, optional) – Label to use for data (used for legend).

  • kwargs – Other arguments are passed to numpy.histogram()

addLegend(**kwargs)[source]

Add legend to histogram.

Parameters:

kwargs – All arguments passed to matplotlib.axes.Axes.legend().

classmethod create(histData, fig=None, figParams={}, ax=None, axParams={}, plot=None, makeInteractive=False, plotType='scatter', axesType='linear', density=True, bins=10, range=None, line='o', label=None, **kwargs)[source]

Create a histogram plot.

Parameters:
  • histData (numpy.ndarray) – Data to be used in the histogram.

  • fig (matplotlib.figure.Figure) – Matplotlib figure to plot on.

  • figParams – Passed to defdap.plotting.Plot.

  • ax (matplotlib.axes.Axes) – Matplotlib axis to plot on.

  • axParams – Passed to defdap.plotting.Plot as axParams.

  • plot (defdap.plotting.HistPlot) – Plot where histgram is created. If none, a new plot is created.

  • makeInteractive (bool, optional) – If true, make plot interactive.

  • plotType (str, {'scatter', 'bar', 'barfilled', 'step'}) – Type of plot to use

  • axesType (str, {'linear', 'logx', 'logy', 'loglog', 'None'}, optional) – If ‘log’ is specified, logarithmic scale is used.

  • density – If true, histogram is normalised such that the integral sums to 1.

  • bins (int) – Number of bins to use for histogram.

  • range (tuple or None, optional) – The lower and upper range of the bins

  • line (str, optional) – Marker or line type to be used.

  • label (str, optional) – Label to use for data (is used for legend).

  • kwargs – Other arguments are passed to defdap.plotting.HistPlot.addHist()

Return type:

defdap.plotting.HistPlot

class defdap.plotting.CrystalPlot(fig=None, ax=None, axParams={}, makeInteractive=False, **kwargs)[source]

Bases: Plot

Class for creating a 3D plot for plotting unit cells.

addVerts(verts, **kwargs)[source]

Plots planes, defined by the vertices provided.

Parameters: