Plotting¶
plotting ¶
This module contains plotting functionality to illustrate sequence definitions in a commonly occuring format.
plot_moment ¶
plot_moment(
seq: Sequence,
moment_order: int = 0,
axes: Union[Tuple[Axes, ...], Axes, str] = None,
start_time: Quantity = None,
) -> plt.Figure
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:
| Name | Type | Description | Default |
|---|---|---|---|
axes
|
Union[Tuple[Axes, ...], Axes, str]
|
(plt.Axes, plt.Axes, plt.Axes) (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 3 separate axes is created. |
None
|
seq
|
Sequence
|
Instance of cmrseq.Sequence |
required |
moment_order
|
int
|
order of the moment to be plotted |
0
|
Returns:
| Type | Description |
|---|---|
plt.figure with 3x1 suplot grid
|
|
Source code in cmrseq/plotting.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
plot_sequence ¶
plot_sequence(
seq: Sequence,
axes: Union[Tuple[Axes, ...], Axes, str] = None,
format_axes: bool = True,
add_legend: bool = True,
adc_yoffset: float = 0,
n_yticks: int = 5,
plot_center_lines: bool = True,
legend_position: str = "upper left",
gradient_style: str = "line",
gradient_colors: List[str] = ("C0", "C1", "C2"),
rf_color: str = "purple",
add_flip_angles: bool = False,
) -> plt.Figure
Plot RF, gradients and adc events into a(4, 1) axes grid. If for axes are specified as argument, plots are inserted there.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seq
|
Sequence
|
Instance of cmrseq.Sequence |
required |
axes
|
Union[Tuple[Axes, ...], Axes, str]
|
(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. |
None
|
format_axes
|
bool
|
if true applies styling to the axes |
True
|
add_legend
|
bool
|
if true adds legend to the first axis. If no axes are provided, this is forced to be True |
True
|
adc_yoffset
|
float
|
determines the y-offset for adc-event markers |
0
|
n_yticks
|
int
|
determines the number of y ticks if format axes is True |
5
|
plot_center_lines
|
bool
|
If True, adds vertical lines for rf-centers and adc-centers |
True
|
legend_position
|
str
|
Position of legend if it is added |
'upper left'
|
gradient_style
|
str
|
if "line" only the line is plotted, if "filled" filled between the axes |
'line'
|
gradient_colors
|
List[str]
|
tuple of 3 colors, the channels are plotted in. |
('C0', 'C1', 'C2')
|
rf_color
|
str
|
determines the color, RF waveforms are plotted. |
'purple'
|
add_flip_angles
|
bool
|
If true, adds text_labels to the RF centers stating the flip angle |
False
|
Source code in cmrseq/plotting.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | |
plot_kspace_2d ¶
plot_kspace_2d(
seq: Sequence,
plot_raster_trajectory: bool = True,
k_axes: Tuple[int, int] = (0, 1),
ax: Axes = None,
format_axes: bool = True,
markersize: int = 15,
map_sampling_times: str = None,
add_colorbar: bool = None,
colorbar_kwargs: dict = None,
) -> plt.Axes
2D-scatter plot the trajectory of the sequence and its adc events
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seq
|
Sequence
|
|
required |
plot_raster_trajectory
|
bool
|
if true plots the k-space points for all gradient raster points |
True
|
k_axes
|
Tuple[int, int]
|
determines which combination of (kx, ky, kz) to scatter plot |
(0, 1)
|
ax
|
Axes
|
plt.Axis, if not None this is used to plot k-space |
None
|
format_axes
|
bool
|
|
True
|
markersize
|
int
|
|
15
|
map_sampling_times
|
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. |
None
|
add_colorbar
|
bool
|
if true a color-bar for the sampling time mapping |
None
|
colorbar_kwargs
|
dict
|
keyword arguments for color bar. Only has an effect if 'add_colorbar==True' |
None
|
Returns:
| Type | Description |
|---|---|
axis used to plot
|
|
Source code in cmrseq/plotting.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
plot_kspace_3d ¶
plot_kspace_3d(
seq: Sequence,
plot_raster_trajectory: bool = False,
axis: Axes = None,
format_axis: bool = True,
marker_kw: dict = None,
line_kw: dict = None,
) -> (plt.Figure, plt.Axes)
3D-scatter plot the trajectory of the sequence and its adc events
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seq
|
Sequence
|
|
required |
plot_raster_trajectory
|
bool
|
if true plots the k-space points for all gradient raster points |
False
|
axis
|
Axes
|
|
None
|
format_axis
|
bool
|
|
True
|
marker_kw
|
dict
|
keyword arguments for sample-markers |
None
|
line_kw
|
dict
|
keyword arguments for gradient trajectory line |
None
|
Source code in cmrseq/plotting.py
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
plot_block_names ¶
plot_block_names(
seq: Sequence, axis: Axes, fontsize: float = 9
)
Plots a time for the given sequence, on which the names of all contained blocks are added at their corresponding start time
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seq
|
Sequence
|
|
required |
axis
|
Axes
|
|
required |
fontsize
|
float
|
|
9
|
Returns:
| Type | Description |
|---|---|
object
|
|
Source code in cmrseq/plotting.py
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | |
plot_slew ¶
plot_slew(
seq: Sequence,
axes: Union[Tuple[Axes, ...], Axes, str] = None,
)
Plots the gradient and slew over time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seq
|
Sequence
|
Instance of cmrseq.Sequence. |
required |
axes
|
Union[Tuple[Axes, ...], Axes, str]
|
Three axes, a single axis, |
None
|
Returns:
| Type | Description |
|---|---|
figure
|
|
Source code in cmrseq/plotting.py
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 | |
plot_gradient_spectra ¶
plot_gradient_spectra(
seq: Sequence,
directions: List[ndarray] = None,
start_time: Quantity = None,
end_time: Quantity = None,
ax: Axes = None,
) -> plt.Figure
Plots gradient sampling spectra for a given sequence along a list of directions. If no directions are given, plots along MPS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seq
|
Sequence
|
Instance of cmrseq.Sequence to plot spectra |
required |
directions
|
List[ndarray]
|
List[np.ndarray of shape (3, )] directions to plot spectra along, default will plot MPS |
None
|
start_time
|
Quantity
|
Quantity[Time] Start time of spectra calculation window |
None
|
end_time
|
Quantity
|
Quantity[Time] End time of spectra calculation window |
None
|
ax
|
Axes
|
plt.Axes axis to place plots into, if not given creates and returns new figure |
None
|
Source code in cmrseq/plotting.py
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 | |
anotate_timing ¶
anotate_timing(
start: Quantity,
end: Quantity,
ypos: float,
text: str,
axis: Axes,
color: str = None,
fontsize: float = 12,
height: float = 2,
rot: float = 0,
vertical_alignment: str = None,
linewidth: float = 2,
) -> None
Adds a line with two vertical ticks and a descriptive text into the given axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
Quantity
|
Start of annotation interval |
required |
end
|
Quantity
|
End of annotation interval |
required |
ypos
|
float
|
position on y-axes in units of the axis |
required |
text
|
str
|
string containing the label |
required |
axis
|
Axes
|
axes object to insert the text into |
required |
color
|
str
|
Color of text and glyph |
None
|
fontsize
|
float
|
Fontsize of annotation |
12
|
height
|
float
|
Height of the annotations vertical ticks in units of the axis |
2
|
rot
|
float
|
Angle in degrees, that the text is rotated |
0
|
vertical_alignment
|
str
|
defaults to top if ypos > 0 otherwise bottom |
None
|
linewidth
|
float
|
Linewidth of the annotion glyph |
2
|
Source code in cmrseq/plotting.py
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 | |
center_axes ¶
center_axes(
axis: Axes,
linewidth: float = 2,
color=(0, 0, 0, 1),
xy: str = "xy",
ticksoff: str = "",
) -> None
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:
| Name | Type | Description | Default |
|---|---|---|---|
axis
|
Axes
|
Axes object to format |
required |
linewidth
|
float
|
Linewidth of the axis spine |
2
|
color
|
Color of the new axis spine |
(0, 0, 0, 1)
|
|
xy
|
str
|
String specifying which axes to modify (x, y, xy) |
'xy'
|
ticksoff
|
str
|
String specifying where to switch of ticks |
''
|
Source code in cmrseq/plotting.py
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 | |