plotting#

Example Usage#

Full Contents:#

plotting.XYZToRGB(xyz)#

ref_X = 0.9505; %Observer = 2 deg Illuminant = D65 ref_Y = 1.000; ref_Z = 1.089;

plotting.coolwarm(m)#

COOLWARM cool-warm color map COOLWARM(M) returns an M-by-3 matrix containing a colormap with cool-to-warm colors, as commonly used in Paraview. COOLWARM, by itself, is the same length as the current colormap.

For example, to reset the colormap of the current figure:

colormap(coolwarm)

Colormap is based on the colors used by the freeware program Paraview. The color table used here is CoolWarmUChar33.csv, from http://www.sandia.gov/~kmorel/documents/ColorMaps/ Reference: Moreland, Kenneth, 2009, Diverging Color Maps for Scientific Visualization, in Proceedings of the 5th International Symposium on Visual Computing. The Matlab code is after haxby.m by Kelsey Jordahl, Marymount Manhattan College.

See also HSV, GRAY, PINK, COOL, BONE, COPPER, FLAG, HOT COLORMAP, RGBPLOT, HAXBY.

plotting.define_colors(varargin)#

DEFINE_COLORS Define a set of pleasant colors Define a set of colors to use

plotting.define_markers(nmarkers)#
DEFINE_MARKERS(nmarkers)

Return cell array of markerstyles (cyclic if nmarkers is large)

Parameters

nmarkers (int) – The number of markers to hold in the array

Returns

  • markers (1 x nmarkers cell array) – The symbols for linespec for each kind of marker

  • NPMitchell 2019

plotting.diverging_cmap(s, rgb1, rgb2)#
This function is based on Kenneth Moreland’s code for greating Diverging

Colormaps. Created by Andy Stein, improved Noah P Mitchell 2019. template accessed from: https://www.kennethmoreland.com/color-maps/

s is a vector that goes between zero and one

Common rgb1, rgb2 pairs are (rgb1, rgb2), (rgb3, rgb4), etc with these each defined below

sarray with values spanning [0, 1]

The values to be mapped to colors, spanning [0, 1]

rgb1length(3) array or int

An RGB triplet for value 0 or an integer indexing common rgb triplets

rgb2length(3) array or int

An RGB triplet for value 1 or an integer indexing common rgb triplets

mapcolormap

A mapping from [0, 1] to colors spanning rgb1 and rgb2, with length(s) possible values.

% Blue to red: bwr = diverging_cmap([0:0.01:1], 1, 2) % Black to white: cmap2 = diverging_cmap([0:0.01:1], [0,0,0], [1,1,1])

plotting.heatmap_on_alphaimage(im, xfield, yfield, cfield, options)#

HEATMAP_ON_IMAGE Plot a scalar field as heatmap on image with opacity This function has some unresolved bugs 2019-10-06: please fix Note: xfield increases from top to bottom of image, yfield from L to R

Parameters
  • im (2d image) –

  • xfield (x values for heatmap, can be ndgrid, linspace, or scattered (not meshgrid)) –

  • yfield (y values for heatmap, can be ndgrid, linspace, or scattered (not meshgrid)) –

  • cfield (scalar field values evaluated at xfield, yfield) –

  • options (struct optionally containing the following) – flipy – whether to flip the heatmap field in Y alpha – opacity value (0, 1) clims – color limits [min max] cmap – colormap

Returns

  • fig (figure instance)

  • ax1 (the image axis)

  • ax2 (the heatmap axis)

  • NPMitchell 2019

plotting.heatmap_on_image(im, xfield, yfield, cfield, options)#

HEATMAP_ON_IMAGE Plot a scalar field as heatmap on image This function has some unresolved bugs 2019-10-06: please fix

Parameters
  • im (2d image) –

  • xfield (x values for heatmap) –

  • yfield (y values for heatmap) –

  • cfield (scalar field values evaluated at xfield, yfield) –

  • options (struct optionally containing the following) – colorstyle – ‘pcolor’, ‘imagesc’, or ‘scatter’ flipy – whether to flip the heatmap field in Y alpha – opacity value (0, 1) clims – color limits [min max] cmap – colormap

Returns

  • fig (figure instance)

  • ax1 (the image axis)

  • ax2 (the heatmap axis)

  • NPMitchell 2019

plotting.interpolate_2color_cmap(s, rgb1, rgb2)#
This function is based on Kenneth Moreland’s code for greating Diverging

Colormaps. Created by Andy Stein, improved Noah P Mitchell 2019. template accessed from: https://www.kennethmoreland.com/color-maps/

s is a vector that goes between zero and one

Common rgb1, rgb2 pairs are (rgb1, rgb2), (rgb3, rgb4), etc with these each defined below

sarray with values spanning [0, 1]

The values to be mapped to colors, spanning [0, 1]

rgb1length(3) array or int

An RGB triplet for value 0 or an integer indexing common rgb triplets

rgb2length(3) array or int

An RGB triplet for value 1 or an integer indexing common rgb triplets

mapcolormap

A mapping from [0, 1] to colors spanning rgb1 and rgb2, with length(s) possible values.

% Blue to red: bwr = diverging_cmap([0:0.01:1], 1, 2) % Black to white: cmap2 = diverging_cmap([0:0.01:1], [0,0,0], [1,1,1])

plotting.interpolate_3color_cmap(s, rgb1, rgb2, rgb3, normalize)#
This function is based on Kenneth Moreland’s code for greating Diverging

Colormaps, modified by Andy Stein. Created by Noah P Mitchell 2019 template accessed from: https://www.kennethmoreland.com/color-maps/

s is a vector that goes between zero and one

Common rgb1, rgb2 pairs are (rgb1, rgb2), (rgb3, rgb4), etc with these each defined below

sarray with values spanning [0, 1]

The values to be mapped to colors, spanning [0, 1]

rgb1length(3) array or int

An RGB triplet for value 0 or an integer indexing common rgb triplets

rgb2length(3) array or int

An RGB triplet for value 1 or an integer indexing common rgb triplets

mapcolormap

A mapping from [0, 1] to colors spanning rgb1 and rgb2, with length(s) possible values.

% Blue to red: bwr = diverging_cmap([0:0.01:1], 1, 2) % Black to white: cmap2 = diverging_cmap([0:0.01:1], [0,0,0], [1,1,1])

plotting.mapValueToColor(vals, vlims, cmap)#
MAPVALUETOCOLOR(vals, vlims, cmap)

map values in vals to colors in colormap cmap given bounds vlims

Parameters
  • vals (N x 1 float/int array) – the values to map to colors

  • vlims (1 x 2 float/int array) – the limits to map to the first and last color in cmap

  • cmap (Mx3 or Mx4 float/int array) – the colormap to map into

Returns

  • colors (N x 3 float/int array) – the colors in the colormap mapped to vals

  • NPMitchell 2020

plotting.plotColoredLinesegs(lsegs, ecolors, varargin)#

PLOTCOLOREDLINESEGS(lsegs, ecolors, varargin)

Parameters
  • lsegs (N x 4 or Nx6 float array) – the linesegments, given as (x0,y0,x1,y1) or (x0,y0,z0,x1,y1,z1)

  • ecolors (N x 3 int array) – color specifications for each lineseg

  • varargin (variable input arguments) – passed to plot() or plot3()

Return type

NPMitchell 2020

plotting.scalarFieldOnImage(im, xx, yy, field, alphaVal, scale, label, varargin)#

SCALARFIELDONIMAGE(im, xx, yy, field, alphaVal, scale, label) Plot a scalar field over an image, colored by magnitude, with const alpha

Parameters
  • im

  • xx (N x 1 float array) – y coordinates of the field evaluation locations

  • yy (M x 1 float array) – y coordinates of the field evaluation locations

  • field (NxM float array) – the scalar field to plot as heatmap

  • alphaVal (float) – the opacity of the heatmap

  • scale (float) – maximum absolute value for the field to be saturated in colormap

  • label (str) – colorbar label, interpreted through Latex by default

  • varargin (keyword arguments (optional, default='diverging')) – options for the plot, with names ‘style’ : ‘diverging’ or ‘positive’ or ‘negative’ ‘interpreter’ : ‘Latex’, ‘default’/’none’

Returns

  • h1 (handle for imshow)

  • h2 (handle for imagesc)

NPMitchell 2020

plotting.scalarFieldOnSurface(faces, vertices, sf, options)#
SCALARVECTORFIELDSONIMAGE(faces, vertices, sf, options)

Plot a scalar field (sf) as heatmap on a 3d mesh surface

facesM x 3 float array

mesh vertex connectivity list (triangulated faces)

verticesN x 3 float array

mesh vertices in 3D

sfNx1 or Mx1 float array

scalar field to plot on surface

qoptsstruct with fields
stylestr (‘diverging’ ‘phase’, default=’diverging’)

style of overlaid scalar field

sscalefloat

scalar field maximum for clims/opacity

alphafloat (optional, used if style ~= ‘phase’)

opacity of overlaid scalar field

outfnstr

path to save image if given

labelstr

colorbar label. Default is ‘$|v|$ [$mu$m / min]’

outfnstr

output filename for figure as png

figWidthint (optional, default = 16)

figure width in cm

figHeightint (optional, default = 10)

figure height in cm

cbarPosition4 x 1 float array

position of the colorbar

Returns

  • h1 (handle for trisurf object)

  • NPMitchell 2020

plotting.scalarVectorFieldsOnImage(im, xxs, yys, sf, xxv, yyv, vx, vy, options)#
SCALARVECTORFIELDSONIMAGE(im, xx, yy, vx, vy, options)

Plot both a scalar field (sf) and vector field (vx,vy) on an image im

imQxRx3 RGB float or int array

the image onto which we overlay the scalar and vector fields. If not RGB, the image will adopt the current colormap.

xxN x 1 float array

x values of PIV grid evaluation points

yyM x 1 float array

y values of PIV grid evaluation points

vxN*M x 1 float array

velocity in x direction

vyN*M x 1 float array

velocity in y direction

qoptsstruct with fields
faces#faces x 3 (optional, if sf is defined on faces)

connectivity list of vertices xxs,yys if sf is defined on faces

stylestr (‘diverging’ ‘phase’)

style of overlaid scalar field, default is diverging If ‘phase’, use ‘options.angle’ to pass vector angles.

angle#faces x 3 (optional, if style == ‘phase’)

scalar field for phasemap. Note that sf signals opacity if style == ‘phase’ and angle will replace sf for color if supplied. Otherwise, sf is used for both.

sscalefloat (optional, used only if style == ‘phase’)

scalar field maximum for opacity/alpha. If zero, color limits are set to min(sf) and max(sf)

alphafloat (optional, used if style ~= ‘phase’)

opacity of overlaid scalar field

outfnstr

path to save image if given

labelstr

colorbar label. Default is ‘$|v|$ [$mu$m / min]’

qsubsampleint

subsampling factor of the quiver field

overlay_quiverbool (default=true)

whether to show the quiverplot overlay

qscalefloat

overall multiplication of the quiver magnitude for overlay (then plotted at true value, “scale=0” in quiver())

outfnstr

output filename for figure as png

figWidthint (optional, default = 16)

figure width in cm

figHeightint (optional, default = 10)

figure height in cm

Returns

  • h1 (handle for imshow)

  • h2 (handle for imagesc)

  • h3 (handle for quiverplot)

  • NPMitchell 2020

plotting.scalarVectorFieldsOnSurface(faces, vertices, sf, xxv, yyv, zzv, vx, vy, vz, options)#
SCALARVECTORFIELDSONIMAGE(im, xx, yy, vx, vy, options)

Plot both a scalar field (sf) as heatmap and vector field (vx,vy) as quiver arrows.

xxN x 1 float array

x values of PIV grid evaluation points

yyM x 1 float array

y values of PIV grid evaluation points

vxN*M x 1 float array

velocity in x direction

vyN*M x 1 float array

velocity in y direction

qoptsstruct with fields
stylestr (‘diverging’ ‘phase’)

style of overlaid scalar field, default is diverging

sscalefloat (optional, used only if style == ‘phase’)

scalar field maximum for opacity/alpha

alphafloat (optional, used if style ~= ‘phase’)

opacity of overlaid scalar field

outfnstr

path to save image if given

labelstr

colorbar label. Default is ‘$|v|$ [$mu$m / min]’

qsubsampleint

subsampling factor of the quiver field

overlay_quiverbool (default=true)

whether to show the quiverplot overlay

qscalefloat

overall multiplication of the quiver magnitude for overlay (then plotted at true value, “scale=0” in quiver())

outfnstr

output filename for figure as png

figWidthint (optional, default = 16)

figure width in cm

figHeightint (optional, default = 10)

figure height in cm

Returns

  • h1 (handle for imshow)

  • h2 (handle for imagesc)

  • h3 (handle for quiverplot)

  • NPMitchell 2020

plotting.texture_patch_3d_heatmap2file(FF, VV, TF, TV, IV, tMapOpts, figOpts)#

TEXTURE_PATCH_3D_HEATMAP2FILE(FF, VV, TF, TV, IV, tMapOpts, figOpts) unfinished? NPMitchell 2020

plotting.vectorFieldHeatPhaseOnImage(im, xyfstruct, vx, vy, vscale, options)#
VECTORFIELDHEATPHASEONIMAGE(im, xyfstruct, vx, vy, vscale, options)

Plot a vector field (vx,vy) evaluated at grid[xx, yy] on an image im

Parameters
  • im (PxQ numeric array) – RGB or grayscale image

  • xyfstruct (struct with fields) –

    xNx1 or (N*M)x1 or NxM float array (required if no field v)

    x coordinates of vector field

    yMx1 or (N*M)x1 or NxM float array (required if no field v)

    y coordinates of vector field

    v(N*M)x2 float array (required if no fields x,y)

    x and y coordinates of vector field

    foptional #faces x 3 int array

    connectivity list of the mesh to color over the image, use only if data is not in

  • vx (N*M x 1 float array) – velocity in x direction

  • vy (N*M x 1 float array) – velocity in y direction

  • vscale (float) – magnitude associated with maximum color/intensity in velocity image

  • qopts (struct with fields) –

    outfnstr

    path to save image if given

    labelstr (default=’$|v|$ [$mu$m / min]’)

    colorbar label. Default is ‘$|v|$ [$mu$m / min]’

    qsubsampleint (default=10)

    subsampling factor of the quiver field

    subsamplingMethodstr (‘farthestPoint’ or ‘random’)

    if nPts > 0 and data is not a structured grid, then subsample the vector field according to this method. FarthestPoint is slow but gives approximately equally spaced vectors in the plane.

    overlay_quiverbool (default=true)

    whether to show the quiverplot overlay

    qscalefloat

    overall scale of the quivers

    outfnstr

    output filename for figure as png

    xlim[minx, maxx]

    minimum and maximum x values in main axis

    ylim[miny, maxy]

    minimimum and maximum y values in main axis

Returns

  • h1 (handle for imshow)

  • h2 (handle for imagesc)

  • h3 (handle for quiverplot)

  • Example usage

  • ————-

  • % Create example image

  • im = peaks ;

  • [xxs, yys] = meshgrid(1 (size(im, 1), 1:size(im, 2)) ;)

  • % Create example velocity field on the same field (here xxv=xxs, yyv=yys)

  • vx = im . xxs * 0.02 ;*

  • vy = im . yys * 0.01 ;*

  • sf = sqrt(vx.^2 + vy.^2) ; % scalar field is velocity magnitude

  • options.angle = atan2(vy, vx) ; % polar field

  • % Supply 1d x and y lists

  • xyf.x = xxs(1, (*) ;*)

  • xyf.y = yys( (, 1)’ ;)

  • vscale = max(abs(sf( (*))) ; % color limit for opacity*)

  • options.visibility = ‘on’ ;

  • options.overlay_quiver = false ;

  • vectorFieldHeatPhaseOnImage(rand(size(im)), xyf, vx, vy, vscale, options) ;

See also

more, less, NPMitchell

plotting.vectorFieldQuiverOnImage(im, xx, yy, vx, vy, vscale, options)#
VECTORFIELDQUIVERONIMAGE(im, xx, yy, vx, vy, vscale, options)

Plot a vector field (vx,vy) evaluated at grid[xx, yy] on an image im as quiverplot (subsampled quiver)

xxN x 1 float array

x values of PIV grid evaluation points

yyM x 1 float array

y values of PIV grid evaluation points

vxN*M x 1 float array

velocity in x direction

vyN*M x 1 float array

velocity in y direction

vscalefloat

magnitude associated with maximum color/intensity in velocity image

qoptsstruct with fields
outfnstr

path to save image if given

labelstr

colorbar label. Default is ‘$|v|$ [$mu$m / min]’

qsubsampleint

subsampling factor of the quiver field

qscalefloat

overall scale of the quivers

outfnstr

output filename for figure as png

Returns

  • h1 (handle for imshow)

  • h3 (handle for quiverplot)

  • NPMitchell 2020

Indices and tables#