phasorpy.plot#

Plot phasor coordinates and related data.

The phasorpy.plot module provides functions and classes to visualize phasor coordinates and related data using the matplotlib library.

class phasorpy.plot.PhasorPlot(allquadrants=None, ax=None, *, frequency=None, grid=True, **kwargs)[source]#

Phasor plot.

Create publication quality visualizations of phasor coordinates.

Parameters:
  • allquadrants (bool, optional) – Show all quandrants of phasor space. By default, only the first quadrant with universal semicircle is shown.

  • ax (matplotlib axes, optional) – Matplotlib axes used for plotting. By default, a new subplot axes is created.

  • frequency (float, optional) – Laser pulse or modulation frequency in MHz.

  • grid (bool, optional, default: True) – Display polar grid or semicircle.

  • **kwargs – Additional properties to set on ax.

property ax#

Matplotlib matplotlib.axes.Axes.

circle(real, imag, /, radius, **kwargs)[source]#

Draw grid circle of radius around center.

Parameters:
  • real (float) – Real component of circle center coordinate.

  • imag (float) – Imaginary component of circle center coordinate.

  • radius (float) – Circle radius.

  • **kwargs – Additional parameters passed to matplotlib.patches.Circle.

components(real, imag, /, fraction=None, labels=None, label_offset=None, **kwargs)[source]#

Plot linear combinations of phasor coordinates or ranges thereof.

Parameters:
  • real ((N,) array_like) – Real component of phasor coordinates.

  • imag ((N,) array_like) – Imaginary component of phasor coordinates.

  • fraction ((N,) array_like, optional) – Weight associated with each component. If None (default), outline the polygon area of possible linear combinations of components. Else, draw lines from the component coordinates to the weighted average.

  • labels (Sequence of str, optional) – Text label for each component.

  • label_offset (float, optional) – Distance of text label to component coordinate.

  • **kwargs – Additional parameters passed to matplotlib.patches.Polygon, matplotlib.lines.Line2D, or matplotlib.axes.Axes.annotate

contour(real, imag, /, **kwargs)[source]#

Plot contours of imag versus real coordinates (not implemented).

Parameters:
  • real (array_like) – Real component of phasor coordinates.

  • imag (array_like) – Imaginary component of phasor coordinates. Must be of same shape as real.

  • **kwargs – Additional parameters passed to numpy.histogram2d() and matplotlib.axes.Axes.contour().

cursor(real, imag, /, real_limit=None, imag_limit=None, radius=None, radius_minor=None, angle=None, align_semicircle=False, **kwargs)[source]#

Plot phase and modulation grid lines and arcs at phasor coordinates.

Parameters:
  • real (float) – Real component of phasor coordinate.

  • imag (float) – Imaginary component of phasor coordinate.

  • real_limit (float, optional) – Real component of limiting phasor coordinate.

  • imag_limit (float, optional) – Imaginary component of limiting phasor coordinate.

  • radius (float, optional) – Radius of circle limiting phase and modulation grid lines and arcs.

  • radius_minor (float, optional) – Radius of elliptic cursor along semi-minor axis. By default, radius_minor is equal to radius, that is, the ellipse is circular.

  • angle (float, optional) – Rotation angle of semi-major axis of elliptic cursor in radians. If None (default), orient ellipse cursor according to align_semicircle.

  • align_semicircle (bool, optional) – Determines elliptic cursor orientation if angle is not provided. If true, align the minor axis of the ellipse with the closest tangent on the universal semicircle, else align to the unit circle.

  • **kwargs – Additional parameters passed to matplotlib.lines.Line2D, matplotlib.patches.Circle, matplotlib.patches.Ellipse, or matplotlib.patches.Arc.

property dataunit_to_point#

Factor to convert data to point unit.

property fig#

Matplotlib matplotlib.figure.Figure.

hist2d(real, imag, /, **kwargs)[source]#

Plot 2D histogram of imag versus real coordinates.

Parameters:
  • real (array_like) – Real component of phasor coordinates.

  • imag (array_like) – Imaginary component of phasor coordinates. Must be of same shape as real.

  • **kwargs – Additional parameters passed to numpy.histogram2d() and matplotlib.axes.Axes.pcolormesh().

imshow(image, /, **kwargs)[source]#

Plot an image, for example, a 2D histogram (not implemented).

Parameters:
  • image (array_like) – Image to display.

  • **kwargs – Additional parameters passed to matplotlib.axes.Axes.imshow().

line(real, imag, /, **kwargs)[source]#

Draw grid line.

Parameters:
  • real (array_like, shape (n, )) – Real components of line start and end coordinates.

  • imag (array_like, shape (n, )) – Imaginary components of line start and end coordinates.

  • **kwargs – Additional parameters passed to matplotlib.lines.Line2D.

Returns:

List containing plotted line.

Return type:

list[matplotlib.lines.Line2D]

plot(real, imag, /, fmt='o', *, label=None, **kwargs)[source]#

Plot imag versus real coordinates as markers and/or lines.

Parameters:
  • real (array_like) – Real component of phasor coordinates. Must be one or two dimensional.

  • imag (array_like) – Imaginary component of phasor coordinates. Must be of same shape as real.

  • fmt (str, optional, default: 'o') – Matplotlib style format string.

  • label (str or sequence of str, optional) – Plot label. May be a sequence if phasor coordinates are two dimensional arrays.

  • **kwargs – Additional parameters passed to matplotlib.axes.Axes.plot().

Returns:

Lines representing data plotted last.

Return type:

list[matplotlib.lines.Line2D]

polar_cursor(phase=None, modulation=None, phase_limit=None, modulation_limit=None, radius=None, radius_minor=None, angle=None, align_semicircle=False, **kwargs)[source]#

Plot phase and modulation grid lines and arcs.

Parameters:
  • phase (float, optional) – Angular component of polar coordinate in radians.

  • modulation (float, optional) – Radial component of polar coordinate.

  • phase_limit (float, optional) – Angular component of limiting polar coordinate (in radians). Modulation grid arcs are drawn between phase and phase_limit.

  • modulation_limit (float, optional) – Radial component of limiting polar coordinate. Phase grid lines are drawn from modulation to modulation_limit.

  • radius (float, optional) – Radius of circle limiting phase and modulation grid lines and arcs.

  • radius_minor (float, optional) – Radius of elliptic cursor along semi-minor axis. By default, radius_minor is equal to radius, that is, the ellipse is circular.

  • angle (float, optional) – Rotation angle of semi-major axis of elliptic cursor in radians. If None (default), orient ellipse cursor according to align_semicircle.

  • align_semicircle (bool, optional) – Determines elliptic cursor orientation if angle is not provided. If true, align the minor axis of the ellipse with the closest tangent on the universal semicircle, else align to the unit circle.

  • **kwargs – Additional parameters passed to matplotlib.lines.Line2D, matplotlib.patches.Circle, matplotlib.patches.Ellipse, or matplotlib.patches.Arc.

polar_grid(**kwargs)[source]#

Draw polar coordinate system.

Parameters:

**kwargs – Parameters passed to matplotlib.patches.Circle and matplotlib.lines.Line2D.

save(file, /, **kwargs)[source]#

Save current figure to file.

Parameters:
  • file (str, path-like, or binary file-like) – Path or Python file-like object to write the current figure to.

  • **kwargs – Additional keyword arguments passed to matplotlib:pyplot.savefig().

semicircle(frequency=None, *, polar_reference=None, phasor_reference=None, lifetime=None, labels=None, show_circle=True, use_lines=False, **kwargs)[source]#

Draw universal semicircle.

Parameters:
  • frequency (float, optional) – Laser pulse or modulation frequency in MHz.

  • polar_reference ((float, float), optional, default: (0, 1)) – Polar coordinates of zero lifetime.

  • phasor_reference ((float, float), optional, default: (1, 0)) – Phasor coordinates of zero lifetime. Alternative to polar_reference.

  • lifetime (sequence of float, optional) – Single component lifetimes at which to draw ticks and labels. Only applies when frequency is specified.

  • labels (sequence of str, optional) – Tick labels. By default, the values of lifetime. Only applies when frequency and lifetime are specified.

  • show_circle (bool, optional, default: True) – Draw universal semicircle.

  • use_lines (bool, optional, default: False) – Draw universal semicircle using lines instead of arc.

  • **kwargs – Additional parameters passed to matplotlib.lines.Line2D or matplotlib.patches.Arc and matplotlib.axes.Axes.plot().

Returns:

Lines representing plotted semicircle and ticks.

Return type:

list[matplotlib.lines.Line2D]

show()[source]#

Display all open figures. Call matplotlib.pyplot.show().

class phasorpy.plot.PhasorPlotFret(*, frequency=60.0, donor_lifetime=4.2, acceptor_lifetime=3.0, fret_efficiency=0.5, donor_freting=1.0, donor_bleedthrough=0.0, acceptor_bleedthrough=0.0, acceptor_background=0.0, donor_background=0.0, background_real=0.0, background_imag=0.0, ax=None, interactive=False, **kwargs)[source]#

FRET phasor plot.

Plot Förster Resonance Energy Transfer efficiency trajectories of donor and acceptor channels in phasor space.

Parameters:
  • frequency (array_like) – Laser pulse or modulation frequency in MHz.

  • donor_lifetime (array_like) – Lifetime of donor without FRET in ns.

  • acceptor_lifetime (array_like) – Lifetime of acceptor in ns.

  • fret_efficiency (array_like, optional, default 0) – FRET efficiency in range [0..1].

  • donor_freting (array_like, optional, default 1) – Fraction of donors participating in FRET. Range [0..1].

  • donor_bleedthrough (array_like, optional, default 0) – Weight of donor fluorescence in acceptor channel relative to fluorescence of fully sensitized acceptor. A weight of 1 means the fluorescence from donor and fully sensitized acceptor are equal. The background in the donor channel does not bleed through.

  • acceptor_bleedthrough (array_like, optional, default 0) – Weight of fluorescence from directly excited acceptor relative to fluorescence of fully sensitized acceptor. A weight of 1 means the fluorescence from directly excited acceptor and fully sensitized acceptor are equal.

  • acceptor_background (array_like, optional, default 0) – Weight of background fluorescence in acceptor channel relative to fluorescence of fully sensitized acceptor. A weight of 1 means the fluorescence of background and fully sensitized acceptor are equal.

  • donor_background (array_like, optional, default 0) – Weight of background fluorescence in donor channel relative to fluorescence of donor without FRET. A weight of 1 means the fluorescence of background and donor without FRET are equal.

  • background_real (array_like, optional, default 0) – Real component of background fluorescence phasor coordinate at frequency.

  • background_imag (array_like, optional, default 0) – Imaginary component of background fluorescence phasor coordinate at frequency.

  • ax (matplotlib axes, optional) – Matplotlib axes used for plotting. By default, a new subplot axes is created. Cannot be used with interactive mode.

  • interactive (bool, optional, default: False) – Use matplotlib slider widgets to interactively control parameters.

  • **kwargs – Additional parameters passed to phasorpy.plot.PhasorPlot.

phasorpy.plot.plot_phasor(real, imag, /, *, style=None, allquadrants=None, frequency=None, show=True, **kwargs)[source]#

Plot phasor coordinates.

A simplified interface to the PhasorPlot class.

Parameters:
  • real (array_like) – Real component of phasor coordinates.

  • imag (array_like) – Imaginary component of phasor coordinates. Must be of same shape as real.

  • style ({'plot', 'hist2d', 'contour'}, optional) – Method used to plot phasor coordinates. By default, if the number of coordinates are less than 65536 and the arrays are less than three-dimensional, ‘plot’ style is used, else ‘hist2d’.

  • allquadrants (bool, optional) – Show all quadrants of phasor space. By default, only the first quadrant is shown.

  • frequency (float, optional) – Frequency of phasor plot. If provided, the universal semicircle is labeled with reference lifetimes.

  • show (bool, optional, default: True) – Display figure.

  • **kwargs – Additional parguments passed to PhasorPlot, PhasorPlot.plot(), PhasorPlot.hist2d(), or PhasorPlot.contour() depending on style.

phasorpy.plot.plot_phasor_image(mean, real, imag, *, harmonics=None, percentile=None, title=None, show=True, **kwargs)[source]#

Plot phasor coordinates as images.

Preview phasor coordinates from time-resolved or hyperspectral image stacks as returned by phasorpy.phasor.phasor_from_signal().

The last two axes are assumed to be the image axes. Harmonics, if any, are in the first axes of real and imag. Other axes are averaged for display.

Parameters:
  • mean (array_like) – Image average. Must be two or more dimensional, or None.

  • real (array_like) – Image of real component of phasor coordinates. The last dimensions must match shape of mean.

  • imag (array_like) – Image of imaginary component of phasor coordinates. Must be same shape as real.

  • harmonics (int, optional) – Number of harmonics to display. If mean is None, a nonzero value indicates the presence of harmonics in the first axes of mean and real. Else, the presence of harmonics is determined from the shapes of mean and real. By default, up to 4 harmonics are displayed.

  • percentile (float, optional) – The (q, 100-q) percentiles of image data are covered by colormaps. By default, the complete value range of mean is covered, for real and imag the range [-1..1].

  • title (str, optional) – Figure title.

  • show (bool, optional, default: True) – Display figure.

  • **kwargs – Additional arguments passed to matplotlib.pyplot.imshow().

Raises:

ValueError – The shapes of mean, real, and image do not match. Percentile is out of range.

phasorpy.plot.plot_polar_frequency(frequency, phase, modulation, *, ax=None, title=None, show=True, **kwargs)[source]#

Plot phase and modulation verus frequency.

Parameters:
  • frequency (array_like, shape (n, )) – Laser pulse or modulation frequency in MHz.

  • phase (array_like) – Angular component of polar coordinates in radians.

  • modulation (array_like) – Radial component of polar coordinates.

  • ax (matplotlib axes, optional) – Matplotlib axes used for plotting. By default, a new subplot axes is created.

  • title (str, optional) – Figure title. The default is “Multi-frequency plot”.

  • show (bool, optional, default: True) – Display figure.

  • **kwargs – Additional arguments passed to matplotlib.pyplot.plot().

phasorpy.plot.plot_signal_image(signal, /, *, axis=None, percentile=None, title=None, show=True, **kwargs)[source]#

Plot average image and signal along axis.

Preview time-resolved or hyperspectral image stacks to be anayzed with phasorpy.phasor.phasor_from_signal().

The last two axes, excluding axis, are assumed to be the image axes. Other axes are averaged for image display.

Parameters:
  • signal (array_like) – Image stack. Must be three or more dimensional.

  • axis (int, optional, default: -1) – Axis over which phasor coordinates would be computed. The default is the last axis (-1).

  • percentile (float or [float, float], optional) – The [q, 100-q] percentiles of image data are covered by colormaps. By default, the complete value range of mean is covered, for real and imag the range [-1..1].

  • title (str, optional) – Figure title.

  • show (bool, optional, default: True) – Display figure.

  • **kwargs – Additional arguments passed to matplotlib.pyplot.imshow().

Raises:

ValueError – Signal is not an image stack. Percentile is out of range.