defdap.plotting module¶
- class defdap.plotting.Plot(ax=None, ax_params={}, fig=None, make_interactive=False, title=None, **kwargs)[source]¶
Bases:
object
Class used for creating and manipulating plots.
- check_interactive()[source]¶
Checks if current plot is interactive.
- Raises:
Exception – If plot is not interactive
- add_axes(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
- add_button(label, click_handler, loc=(0.8, 0.0, 0.1, 0.07), **kwargs)[source]¶
Add a button to the plot.
- Parameters:
label (str) – Label for the button.
click_handler – Click handler to assign.
kwargs – All other arguments passed to
matplotlib.widgets.Button
.
- add_text_box(label, submit_handler=None, change_handler=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.
submit_handler – Submit handler to assign.
change_handler – Change handler to assign.
kwargs – All other arguments passed to
matplotlib.widgets.TextBox
.
- Return type:
matplotlotlib.widgets.TextBox
- add_text(ax, x, y, txt, **kwargs)[source]¶
Add text to the plot.
- Parameters:
ax (matplotlib.axes.Axes) – Matplotlib axis to plot on.
x (float) – x position.
y (float) – y position.
txt (str) – Text to write onto the plot.
kwargs – All other arguments passed to
matplotlib.pyplot.text()
.
- add_arrow(start_end, persistent=False, clear_previous=True, label=None)[source]¶
Add arrow to grain plot.
- Parameters:
start_end (4-tuple) – Starting (x, y), Ending (x, y).
persistent – If persistent, do not clear arrow with clearPrev.
clear_previous – Clear all non-persistent arrows.
label – Label to place near arrow.
- line_slice(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.add_event_handler('button_press_event',lambda e, p: line_slice(e, p)) >>> plot.add_event_handler('button_release_event', lambda e, p: line_slice(e, p))
- property exists¶
- class defdap.plotting.MapPlot(calling_map, fig=None, ax=None, ax_params={}, make_interactive=False, **kwargs)[source]¶
Bases:
Plot
Class for creating a map plot.
- add_map(map_data, vmin=None, vmax=None, cmap='viridis', **kwargs)[source]¶
Add a map to a plot.
- Parameters:
map_data (numpy.ndarray) – Map data to plot.
vmin (float) – Minimum value for the colour scale.
vmax (float) – Maximum value for the colour scale.
cmap – Colour map.
kwargs – Other arguments are passed to
matplotlib.pyplot.imshow()
.
- Return type:
- add_colour_bar(label, layer=0, **kwargs)[source]¶
Add a colour bar to plot.
- Parameters:
label (str) – Label for the colour bar.
layer (int) – Layer ID.
kwargs – Other arguments are passed to
matplotlib.pyplot.colorbar()
.
- add_scale_bar(scale=None)[source]¶
Add scale bar to plot.
- Parameters:
scale (float) – Size of a pixel in microns.
- add_grain_boundaries(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, defdap.ebsd.BoundarySet) – 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.
boundaries – Boundaries to plot. 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
- add_grain_highlights(grain_ids, grain_colours=None, alpha=None, new_layer=False)[source]¶
Highlight grains in the plot.
- Parameters:
- Return type:
- add_grain_numbers(fontsize=10, **kwargs)[source]¶
Add grain numbers to a map.
- Parameters:
fontsize (float) – Font size.
kwargs – Pass other arguments to
matplotlib.pyplot.text()
.
- add_legend(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()
.
- add_points(x, y, update_layer=None, **kwargs)[source]¶
Add points to plot.
- Parameters:
x (list of float) – x coordinates
y (list of float) – y coordinates
update_layer (int, optional) – Layer to place points on
kwargs – Other arguments passed to
matplotlib.pyplot.scatter()
.
- classmethod create(calling_map, map_data, fig=None, fig_params={}, ax=None, ax_params={}, plot=None, make_interactive=False, plot_colour_bar=False, vmin=None, vmax=None, cmap=None, clabel='', plot_gbs=False, dilate_boundaries=False, boundary_colour=None, plot_scale_bar=False, scale=None, highlight_grains=None, highlight_colours=None, highlight_alpha=None, **kwargs)[source]¶
Create a plot for a map.
- Parameters:
calling_map (base.Map) – DIC or EBSD map which called this plot.
map_data (numpy.ndarray) – Data to be plotted.
fig (matplotlib.figure.Figure) – Matplotlib figure to plot on.
fig_params – Passed to defdap.plotting.Plot.
ax (matplotlib.axes.Axes) – Matplotlib axis to plot on.
ax_params – Passed to defdap.plotting.Plot as ax_params.
plot (defdap.plotting.Plot) – If none, use current plot.
make_interactive – If true, make plot interactive
plot_colour_bar (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.
plot_gbs (bool) – If true, plot the grain boundaries on the map.
dilate_boundaries (bool) – If true, dilate the grain boundaries.
boundary_colour (str) – Colour to use for the grain boundaries.
plot_scale_bar (bool) – If true, plot a scale bar in the map.
scale (float) – Size of pixel in microns.
highlight_grains (list(int)) – List of grain IDs to highlight.
highlight_colours (str) – Colour to highlight grains.
highlight_alpha (float) – Alpha (transparency) by which to highlight grains.
kwargs – All other arguments passed to
defdap.plotting.MapPlot.add_map()
- Return type:
- class defdap.plotting.GrainPlot(calling_grain, fig=None, ax=None, ax_params={}, make_interactive=False, **kwargs)[source]¶
Bases:
Plot
Class for creating a map for a grain.
- addMap(map_data, vmin=None, vmax=None, cmap='viridis', **kwargs)[source]¶
Add a map to a grain plot.
- Parameters:
map_data (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:
- add_colour_bar(label, layer=0, **kwargs)[source]¶
Add colour bar to grain plot.
- Parameters:
label (str) – Label to add to colour bar.
layer (int) – Layer on which to add colourbar.
kwargs – Other arguments passed to
matplotlib.pyplot.colorbar()
.
- add_scale_bar(scale=None)[source]¶
Add scale bar to grain plot.
- Parameters:
scale (float) – Size of pixel in micron.
- add_traces(angles, colours, top_only=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.
top_only (bool, optional) – If true, plot only a semicircle instead of a circle.
pos (tuple) – Position of slip traces.
kwargs – Other arguments are passed to
matplotlib.pyplot.quiver()
- add_slip_traces(top_only=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.
top_only (bool, optional) – If true, plot only a semicircle instead of a circle.
pos (tuple) – Position of slip traces.
kwargs – Other arguments are passed to
matplotlib.pyplot.quiver()
- add_slip_bands(top_only=False, grain_map_data=None, angles=None, pos=None, thres=None, min_dist=None, **kwargs)[source]¶
Add lines representing slip bands detected by Radon transform in
calc_slip_bands()
.- Parameters:
top_only (bool, optional) – If true, plot only a semicircle instead of a circle.
grain_map_data – Map data to pass to
calc_slip_bands()
.angles (list(float), optional) – List of angles to plot, otherwise, use angles detected in
calc_slip_bands()
.pos (tuple) – Position in which to plot slip traces.
thres (float) – Threshold to use in
calc_slip_bands()
.min_dist – Minimum angle between bands in
calc_slip_bands()
.kwargs – Other arguments are passed to
matplotlib.pyplot.quiver()
.
- classmethod create(calling_grain, map_data, fig=None, fig_params={}, ax=None, ax_params={}, plot=None, make_interactive=False, plot_colour_bar=False, vmin=None, vmax=None, cmap=None, clabel='', plot_scale_bar=False, scale=None, plot_slip_traces=False, plot_slip_bands=False, **kwargs)[source]¶
Create grain plot.
- Parameters:
calling_grain (base.Grain) – DIC or EBSD grain which called this plot.
map_data – Data to be plotted.
fig (matplotlib.figure.Figure) – Matplotlib figure to plot on.
fig_params – Passed to defdap.plotting.Plot.
ax (matplotlib.axes.Axes) – Matplotlib axis to plot on.
ax_params – Passed to defdap.plotting.Plot as ax_params.
plot (defdap.plotting.Plot) – If none, use current plot.
make_interactive – If true, make plot interactive
plot_colour_bar (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.
plot_scale_bar (bool) – If true, plot a scale bar in the map.
scale (float) – Size of pizel in microns.
plot_slip_traces (bool) – If true, plot slip traces with
add_slip_traces()
plot_slip_bands (bool) – If true, plot slip traces with
add_slip_bands()
kwargs – All other arguments passed to
defdap.plotting.GrainPlot.add_map()
- Return type:
- class defdap.plotting.PolePlot(plot_type, crystal_sym, projection=None, fig=None, ax=None, ax_params={}, make_interactive=False, **kwargs)[source]¶
Bases:
Plot
Class for creating an inverse pole figure plot.
- add_axis()[source]¶
Draw axes on the IPF based on crystal symmetry.
- Raises:
NotImplementedError – If a crystal type other than ‘cubic’ or ‘hexagonal’ are selected.
- add_line(start_point, end_point, plot_syms=False, res=100, **kwargs)[source]¶
Draw lines on the IPF plot.
- Parameters:
start_point (numpy.ndarray) – Start point in crystal coordinates (i.e. [0,0,1]).
end_point (numpy.ndarray) – End point in crystal coordinates, (i.e. [1,0,0]).
plot_syms (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()
.
- label_point(point, label, pad_x=0, pad_y=0, **kwargs)[source]¶
Place a label near a coordinate in the pole plot.
- add_points(alpha_ang, beta_ang, marker_colour=None, marker_size=None, **kwargs)[source]¶
Add a point to the pole plot.
- Parameters:
alpha_ang – Inclination angle to plot.
beta_ang – Azimuthal angle (around z axis from x in anticlockwise as per ISO) to plot.
marker_colour (str or list(str), optional) – Colour of marker. If two specified, then the point will have two semicircles of different colour.
marker_size (float) – Size of marker.
kwargs – Other arguments are passed to
matplotlib.axes.Axes.scatter()
.
- Raises:
Exception – If more than two colours are specified
- add_colour_bar(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()
.
- add_legend(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 stereo_project(*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:
- Raises:
Exception – If input array has incorrect length
- static lambert_project(*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:
- Raises:
Exception – If input array has incorrect length
- class defdap.plotting.HistPlot(plot_type='scatter', axes_type='linear', density=True, fig=None, ax=None, ax_params={}, make_interactive=False, **kwargs)[source]¶
Bases:
Plot
Class for creating a histogram.
- add_hist(hist_data, bins=100, range=None, line='o', label=None, **kwargs)[source]¶
Add a histogram to the current plot
- Parameters:
hist_data (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()
- add_legend(**kwargs)[source]¶
Add legend to histogram.
- Parameters:
kwargs – All arguments passed to
matplotlib.axes.Axes.legend()
.
- classmethod create(hist_data, fig=None, fig_params={}, ax=None, ax_params={}, plot=None, make_interactive=False, plot_type='scatter', axes_type='linear', density=True, bins=10, range=None, line='o', label=None, **kwargs)[source]¶
Create a histogram plot.
- Parameters:
hist_data (numpy.ndarray) – Data to be used in the histogram.
fig (matplotlib.figure.Figure) – Matplotlib figure to plot on.
fig_params – Passed to defdap.plotting.Plot.
ax (matplotlib.axes.Axes) – Matplotlib axis to plot on.
ax_params – Passed to defdap.plotting.Plot as ax_params.
plot (defdap.plotting.HistPlot) – Plot where histgram is created. If none, a new plot is created.
make_interactive (bool, optional) – If true, make plot interactive.
plot_type (str, {'scatter', 'bar', 'barfilled', 'step'}) – Type of plot to use
axes_type (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.add_hist()
- Return type:
- class defdap.plotting.CrystalPlot(fig=None, ax=None, ax_params={}, make_interactive=False, **kwargs)[source]¶
Bases:
Plot
Class for creating a 3D plot for plotting unit cells.
- add_verts(verts, **kwargs)[source]¶
Plots planes, defined by the vertices provided.
- Parameters:
verts (list) – List of vertices.
kwargs – Other arguments are passed to
matplotlib.collections.PolyCollection
.