xdesign.plot

Contains functions for visualizing Phantom and ImageQuality metrics.

DEFAULT_COLOR_MAP : matplotlib.colors.Colormap
The color map used to choose property colors.
DEFAULT_COLOR : matplotlib.colors
The face color of geometry.
POLY_COLOR : matplotlib.colors
The face color of polygons.
DEFAULT_EDGE_COLOR : matplotlib.colors
The color of geometry edges.
POLY_EDGE_COLOR : matplotlib.colors
The color of polygon edges.
LABEL_COLOR : matplotlib.colors
The color of number labels on phantom plots.
POLY_LINEWIDTH : float
The edge width for polygons. See matplotlib.patches.Patch.set_linewidth().
CURVE_LINEWIDTH : float
The edge width for curves. See matplotlib.patches.Patch.set_linewidth().
PLOT_STYLES :
A list of 126 unique line styles.

Classes:

Phantom Plotting Functions:

sidebyside(p[, size, labels, prop, figsize, dpi]) Displays the geometry and the discrete property function of the given Phantom side by side.
discrete_phantom(phantom, size[, ratio, …]) Return a discrete map of the property in the phantom.
plot_phantom(phantom[, axis, labels, …]) Plot a Phantom to the given axis.
plot_mesh(mesh[, axis, alpha, c]) Plot a Mesh to the given axis.
plot_polygon(polygon[, axis, alpha, c]) Plot a Polygon to the given axis.
plot_curve(curve[, axis, alpha, c]) Plot a Curve to the given axis.

Metrics Plotting Functions:

plot_coverage_anisotropy(coverage_map, **kwargs) Plot the coverage anisotropy using 2D glyphs.
plot_metrics(imqual) Plot full reference metrics of ImageQuality data.
plot_mtf(faxis, MTF[, labels]) Plot the MTF.
plot_nps(X, Y, NPS) Plot the 2D frequency plot for the NPS.
plot_neq(freq, NEQ) Plot the NEQ.
get_pie_glyphs(xy, values[, color, trace_normal]) Returns a list of pie glyphs at coordinates xy representing values
xdesign.plot.get_pie_glyphs(xy, values, color='coverage', trace_normal=1, **kwargs)[source]

Returns a list of pie glyphs at coordinates xy representing values

The areas of the pie sectors are proportional to the elements of the vector that the glyph represents. The default color of the Glyph is determined by the sum of the values divided by the trace_normal and the plot.DEFAULT_COLOR_MAP.

Parameters:
  • xy ((M, 2) float) – Locations of glyph centers

  • values ((M, N) float) – Bin sizes for each glyph

  • color (string) –

    coverage

    The color is determined by the sum of the values.

    standard deviation

    The color is standard deviation of the bins

    Kullback-Leibler

    The color is the Kullback-Leibler devation

    random

    The color is randomly assigned from the DEFAULT_COLOR_MAP.

  • trace_normal (float) – A scalar used to normalize the trace for coloring the glyph.

  • kwargs (dict) – Arguments passed to the patches constructor

xdesign.plot.plot_coverage_anisotropy(coverage_map, **kwargs)[source]

Plot the coverage anisotropy using 2D glyphs.

Parameters:kwargs – Keyword arguments for the Glyphs.

See also

metrics.coverage_approx(), Glyph

xdesign.plot.plot_phantom(phantom, axis=None, labels=None, c_props=[], c_map=None, i=-1, z=0.0, t=0.0001)[source]

Plot a Phantom to the given axis.

Parameters:
  • phantom (Phantom) – A phantom to be plotted.
  • axis (matplotlib.axis.Axis) – The axis where the phantom should be plotted. None creates a new axis.
  • labels (bool, optional) – True : Each Phantom given a unique number.
  • c_props (list of str, optional) – List of Phantom properties to use for colormapping the geometries. [] colors the geometries by type.
  • c_map (function, optional) – A function which takes the list of prop(s) for a Phantom as input and returns a matplolib color specifier. [Hunter:07]
xdesign.plot.plot_geometry(geometry, axis=None, alpha=None, c=None, z=0.0, t=0.0001)[source]

Plot a Entity on the given axis.

Parameters:
  • geometry (Entity) – A geometry to plot on the given axis.
  • axis (matplotlib.axis.Axis, optional) – The axis where the geometry should be plotted. None creates a new axis.
  • alpha (float, optional) – The plot opaqueness. 0 is transparent. 1 is opaque.
  • c (matplotlib.colors, optional) – The color of the plotted geometry.
xdesign.plot.plot_mesh(mesh, axis=None, alpha=None, c=None)[source]

Plot a Mesh to the given axis.

Parameters:
  • mesh (Mesh) – A Mesh to plot on the given axis.
  • axis (matplotlib.axis.Axis, optional) – The axis where the Mesh should be plotted. None creates a new axis.
  • alpha (float, optional) – The plot opaqueness. 0 is transparent. 1 is opaque.
  • c (matplotlib.colors, optional) – The color of the plotted Mesh.
xdesign.plot.plot_polygon(polygon, axis=None, alpha=None, c=None)[source]

Plot a Polygon to the given axis.

Parameters:
  • polygon (Polygon) – A Polygon to plot on the given axis.
  • axis (matplotlib.axis.Axis, optional) – The axis where the Polygon should be plotted. None creates a new axis.
  • alpha (float, optional) – The plot opaqueness. 0 is transparent. 1 is opaque.
  • c (matplotlib.colors, optional) – The color of the plotted Polygon.
xdesign.plot.plot_curve(curve, axis=None, alpha=None, c=None)[source]

Plot a Curve to the given axis.

Parameters:
  • curve (Curve) – A Curve to plot on the given axis.
  • axis (matplotlib.axis.Axis, optional) – The axis where the Curve should be plotted. None creates a new axis.
  • alpha (float, optional) – The plot opaqueness. 0 is transparent. 1 is opaque.
  • c (matplotlib.colors, optional) – The color of the plotted curve.
xdesign.plot.discrete_phantom(phantom, size, ratio=9, uniform=True, prop='linear_attenuation')[source]

Return a discrete map of the property in the phantom.

The values of overlapping phantom.Phantom are additive.

Parameters:
  • phantom (phantom.Phantom)
  • size (scalar) – The side length in pixels of the resulting 1 by 1 cm image.
  • ratio (scalar, optional (default: 9)) – The antialiasing works by supersampling. This parameter controls how many pixels in the larger representation are averaged for the final representation. e.g. if ratio = 9, then the final pixel values are the average of 81 pixels.
  • uniform (boolean, optional (default: True)) – When set to False, changes the way pixels are averaged from a uniform weights to gaussian weigths.
  • prop (str, optional (default: linear_attenuation)) – The name of the property to discretize
Returns:

  • image (numpy.ndarray) – The discrete representation of the Phantom that is size x size. 0 if phantom has no geometry or material property.
  • Raise
  • —–
  • ValueError – If size is less than or equal to 0

xdesign.plot.combine_grid(Amin, A, Bmin, B)[source]

Add grid B to grid A by aligning min corners and clipping B

Parameters:
  • Amin, Bmin (int tuple) – The coordinates of the minimum corner of A and B
  • A, B (numpy.ndarray) – The two arrays to add to each other
Returns:

  • AB (numpy.ndarray) – The combined grid
  • Raise
  • —–
  • ValueError – If A and B are do not have the same number of dimensions

xdesign.plot.discrete_geometry(geometry, psize, ratio=9)[source]

Draw the geometry onto a patch the size of its bounding box.

Parameters:
  • geometry (geometry.Entity) – A geometric object with dim, bounding_box, and contains methods
  • psize (float [cm]) – The real size of the pixels in the discrete image
  • ratio (int (default: 9)) – The supersampling ratio for antialiasing. 1 means no antialiasing
Returns:

  • corner (1darray [cm]) – The min corner of the patch
  • patch (ndarray) – The discretized geometry in it’s bounding box
  • Raise
  • —–
  • ValueError – If ratio is less than 1 or psize is less than or equal to 0.

xdesign.plot.sidebyside(p, size=100, labels=None, prop='mass_attenuation', figsize=(6, 3), dpi=100, **kwargs)[source]

Displays the geometry and the discrete property function of the given Phantom side by side.

xdesign.plot.multiroll(x, shift, axis=None)[source]

Roll an array along each axis.

Parameters:
  • x (array_like) – Array to be rolled.
  • shift (sequence of int) – Number of indices by which to shift each axis.
  • axis (sequence of int, optional) – The axes to be rolled. If not given, all axes is assumed, and len(shift) must equal the number of dimensions of x.
Returns:

y (numpy array, with the same type and size as x) – The rolled array.

Notes

The length of x along each axis must be positive. The function does not handle arrays that have axes with length 0.

See also

numpy.roll()

Example

Here’s a two-dimensional array:

>>> x = np.arange(20).reshape(4,5)
>>> x
array([[ 0,  1,  2,  3,  4],
       [ 5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14],
       [15, 16, 17, 18, 19]])

Roll the first axis one step and the second axis three steps:

>>> multiroll(x, [1, 3])
array([[17, 18, 19, 15, 16],
       [ 2,  3,  4,  0,  1],
       [ 7,  8,  9,  5,  6],
       [12, 13, 14, 10, 11]])

That’s equivalent to:

>>> np.roll(np.roll(x, 1, axis=0), 3, axis=1)
array([[17, 18, 19, 15, 16],
       [ 2,  3,  4,  0,  1],
       [ 7,  8,  9,  5,  6],
       [12, 13, 14, 10, 11]])

Not all the axes must be rolled. The following uses the axis argument to roll just the second axis:

>>> multiroll(x, [2], axis=[1])
array([[ 3,  4,  0,  1,  2],
       [ 8,  9,  5,  6,  7],
       [13, 14, 10, 11, 12],
       [18, 19, 15, 16, 17]])

which is equivalent to:

>>> np.roll(x, 2, axis=1)
array([[ 3,  4,  0,  1,  2],
       [ 8,  9,  5,  6,  7],
       [13, 14, 10, 11, 12],
       [18, 19, 15, 16, 17]])

References

Warren Weckesser

xdesign.plot.plot_metrics(imqual)[source]

Plot full reference metrics of ImageQuality data.

Parameters:imqual (ImageQuality) – The data to plot.

References

Colors taken from this gist

xdesign.plot.plot_mtf(faxis, MTF, labels=None)[source]

Plot the MTF. Return the figure reference.

xdesign.plot.plot_nps(X, Y, NPS)[source]

Plot the 2D frequency plot for the NPS. Return the figure reference.

xdesign.plot.plot_neq(freq, NEQ)[source]

Plot the NEQ. Return the figure reference.