Plotting#

This module contains plotting functionality to illustrate sequence definitions in a commonly occuring format.

Functions:

anotate_timing(start, end, ypos, text, axis)

Adds a line with two vertical ticks and a descriptive text into the given axes.

center_axes(axis[, linewidth, color, xy, ...])

Formats the given axes object, such that the spine of desired axes (xy) is rendered as arrow in the of the plot, rather than the outer box.

plot_block_names(seq, axis[, fontsize])

Plots a time for the given sequence, on which the names of all contained blocks are added at their corresponding start time

plot_gradient_spectra(seq[, directions, ...])

Plots gradient sampling spectra for a given sequence along a list of directions.

plot_kspace_2d(seq[, ...])

2D-scatter plot the trajectory of the sequence and its adc events

plot_kspace_3d(seq[, ...])

3D-scatter plot the trajectory of the sequence and its adc events

plot_moment(seq[, moment_order, axes])

Creates a figure with a 3x1 subplot grid and plots the gradient moment

plot_sequence(seq[, axes, format_axes, ...])

Plot RF, gradients and adc events into a(4, 1) axes grid.

anotate_timing(start, end, ypos, text, axis, color=None, fontsize=12, height=2, rot=0, vertical_alignment=None, linewidth=2)[source]#

Adds a line with two vertical ticks and a descriptive text into the given axes.

Parameters:
  • start (Quantity) – Start of annotation interval

  • end (Quantity) – End of annotation interval

  • ypos (float) – position on y-axes in units of the axis

  • text (str) – string containing the label

  • axis (Axes) – axes object to insert the text into

  • color (Optional[str]) – Color of text and glyph

  • fontsize (float) – Fontsize of annotation

  • height (float) – Height of the annotations vertical ticks in units of the axis

  • rot (float) – Angle in degrees, that the text is rotated

  • vertical_alignment (Optional[str]) – defaults to top if ypos > 0 otherwise bottom

  • linewidth (float) – Linewidth of the annotion glyph

Return type:

None

center_axes(axis, linewidth=2, color=(0, 0, 0, 1), xy='xy', ticksoff='')[source]#

Formats the given axes object, such that the spine of desired axes (xy) is rendered as arrow in the of the plot, rather than the outer box.

Parameters:
  • axis (Axes) – Axes object to format

  • linewidth (float) – Linewidth of the axis spine

  • color – Color of the new axis spine

  • xy (str) – String specifying which axes to modify (x, y, xy)

  • ticksoff (str) – String specifying where to switch of ticks

Return type:

None

plot_block_names(seq, axis, fontsize=9)[source]#

Plots a time for the given sequence, on which the names of all contained blocks are added at their corresponding start time

Parameters:
  • seq (Sequence) –

  • axis (Axes) –

  • fontsize (float) –

Returns:

plot_gradient_spectra(seq, directions=None, start_time=None, end_time=None, ax=None)[source]#

Plots gradient sampling spectra for a given sequence along a list of directions. If no directions are given, plots along MPS

Parameters:
  • seq (Sequence) – Instance of cmrseq.Sequence to plot spectra

  • directions (Optional[List[ndarray]]) – List[np.ndarray of shape (3, )] directions to plot spectra along, default will plot MPS

  • start_time (Optional[Quantity]) – Quantity[Time] Start time of spectra calculation window

  • end_time (Optional[Quantity]) – Quantity[Time] End time of spectra calculation window

  • ax (Optional[Axes]) – plt.Axes axis to place plots into, if not given creates and returns new figure

Return type:

Figure

plot_kspace_2d(seq, plot_raster_trajectory=True, k_axes=(0, 1), ax=None, format_axes=True, markersize=15, map_sampling_times=None, add_colorbar=None, colorbar_kwargs=None)[source]#

2D-scatter plot the trajectory of the sequence and its adc events

Parameters:
  • seq (Sequence) –

  • plot_raster_trajectory (bool) – if true plots the k-space points for all gradient raster points

  • k_axes (Tuple[int, int]) – determines which combination of (kx, ky, kz) to scatter plot

  • ax (Optional[Axes]) – plt.Axis, if not None this is used to plot k-space

  • format_axes (bool) –

  • markersize (int) –

  • map_sampling_times (Optional[str]) – str from [None, “global”, “relative”]. For ‘global’, the reference point is 0 ms for ‘relative’ the temporal difference to the center k-space sample is used as reference.

  • add_colorbar (Optional[bool]) – if true a color-bar for the sampling time mapping

  • colorbar_kwargs (Optional[dict]) – keyword arguments for color bar. Only has an effect if ‘add_colorbar==True’

Return type:

Axes

Returns:

axis used to plot

plot_kspace_3d(seq, plot_raster_trajectory=False, axis=None, format_axis=True, marker_kw=None, line_kw=None)[source]#

3D-scatter plot the trajectory of the sequence and its adc events

Parameters:
  • seq (Sequence) –

  • plot_raster_trajectory (bool) – if true plots the k-space points for all gradient raster points

  • axis

  • format_axis (bool) –

  • marker_kw (Optional[dict]) – keyword arguments for sample-markers

  • line_kw (Optional[dict]) – keyword arguments for gradient trajectory line

Return type:

(Figure, Axes)

plot_moment(seq, moment_order=0, axes=None)[source]#
Creates a figure with a 3x1 subplot grid and plots the gradient moment

of specified order for all 3 gradient components over time. Also plots gradients superimposed into the corresponding subplot

Parameters:
  • axes (Union[Tuple[Axes, ...], Axes, str, None]) – (plt.Axes, plt.Axes, plt.Axes, plt.Axes) (rf, gx, gy, gz) or a single instance of plt.Axes if everything shall be plotted in the same axis. If the value is set to string “single”, a new figure is created plotting everything into a single axis. If none a new figure with 4 separate axes is created.

  • seq (Sequence) – Instance of cmrseq.Sequence

  • moment_order (int) – order of the moment to be plotted

Return type:

Figure

Returns:

plt.figure with 3x1 suplot grid

plot_sequence(seq, axes=None, format_axes=True, add_legend=True, adc_yoffset=0, n_yticks=5, plot_center_lines=True, legend_position='upper left', gradient_style='line', gradient_colors=('C0', 'C1', 'C2'), rf_color='purple', add_flip_angles=False)[source]#

Plot RF, gradients and adc events into a(4, 1) axes grid. If for axes are specified as argument, plots are inserted there.

Parameters:
  • seq (Sequence) – Instance of cmrseq.Sequence

  • axes (Union[Tuple[Axes, ...], Axes, str, None]) – (plt.Axes, plt.Axes, plt.Axes, plt.Axes) (rf, gx, gy, gz) or a single instance of plt.Axes if everything shall be plotted in the same axis. If the value is set to string “single”, a new figure is create plotting everyting into a single axis. If none a new figure with 4 separate axes is created.

  • format_axes (bool) – if true applies styling to the axes

  • add_legend (bool) – if true adds legend to the first axis. If no axes are provided, this is forced to be True

  • adc_yoffset (float) – determines the y-offset for adc-event markers

  • n_yticks (int) – determines the number of y ticks if format axes is True

  • plot_center_lines (bool) – If True, adds vertical lines for rf-centers and adc-centers

  • legend_position (str) – Position of legend if it is added

  • gradient_style (str) – if “line” only the line is plotted, if “filled” filled between the axes

  • gradient_colors (List[str]) – tuple of 3 colors, the channels are plotted in.

  • rf_color (str) – determines the color, RF waveforms are plotted.

  • add_flip_angles (bool) – If true, adds text_labels to the RF centers stating the flip angle

Return type:

Figure