cellects.display.plot
cellects.display.plot
This script contains functions to make graphical representation of the dynamical descriptors extracted from Cellects
curve(y, x=None, y_label='', x_label='', color=None, save_path=None)
Plot a one‑dimensional curve with customizable appearance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
array - like
|
Sequence of y‑coordinates to plot. |
required |
x
|
array - like
|
Sequence of x‑coordinates. If |
None
|
y_label
|
str
|
Label for the y‑axis. Default is |
''
|
x_label
|
str
|
Label for the x‑axis. Default is |
''
|
color
|
color spec
|
Matplotlib colour specification used for the line. If |
None
|
save_path
|
str
|
File path to save the figure. If |
None
|
Returns:
| Type | Description |
|---|---|
None
|
The function either displays the figure or writes it to
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Notes
- If all values in
yare greater than10000or smaller than0.001, the y‑axis uses a scientific‑notation formatter. - The figure size is fixed at 10 × 10 inches; saved figures use a DPI of 500 with a tight layout and minimal padding.
transparent=Trueis used when saving, making the background invisible.
Examples:
>>> y = [i**2 for i in range(10)]
>>> curve(y, y_label='y', x_label='x')
# A window displaying the plot of y = x² appears.
>>> x = list(range(10))
>>> curve(y, x=x, color='red', save_path='quadratic.png')
# The plot is saved to ``quadratic.png`` without being shown.
Source code in src/cellects/display/plot.py
draw_arrow(canvas, start_point, end_point, color=(0, 0, 0), thickness=2, head_size=15)
Draw an anti‑aliased arrow on an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
canvas
|
ndarray
|
BGR image on which the arrow is rendered; the array is modified in‑place. |
required |
start_point
|
tuple of int
|
|
required |
end_point
|
tuple of int
|
|
required |
color
|
tuple of int
|
BGR colour of the arrow; defaults to black |
(0, 0, 0)
|
thickness
|
int
|
Line thickness of the arrow shaft; defaults to |
2
|
head_size
|
int
|
Length of each side of the triangular arrowhead; defaults to |
15
|
Returns:
| Type | Description |
|---|---|
None
|
The function modifies |
Notes
- The function uses OpenCV's
cv2.linewithLINE_AAfor anti‑aliased drawing. - The shaft is shortened by
head_sizepixels to avoid overlapping the filled arrowhead drawn withcv2.fillConvexPoly. head_sizeis interpreted in pixel units; very large values may cause the arrowhead to exceed the image boundaries.
Examples:
>>> canvas = np.zeros((120, 160, 3), dtype=np.uint8)
>>> draw_arrow(canvas, (20, 30), (100, 90),
... color=(0, 255, 0), thickness=3, head_size=12)
>>> # ``canvas`` now contains a green arrow from (20
Source code in src/cellects/display/plot.py
get_colony_average_direction(colony_centroids)
Compute the average direction taken by colonies from their first to last position.
The direction is computed from initial to final centroid location in polar coordinates, with y-axis reversed due to image data convention (0 at top, increasing downward).
Parameters: colony_centroids (pd.DataFrame): DataFrame containing colony centroids over time. Expected columns: 'time', 'colony', 'y', 'x'.
Returns: dict: {colony_id: average direction in radians}
Example: >>> df = pd.read_csv('centroids.csv') >>> directions = get_colony_average_direction(df) >>> print(directions[1]) 0.785398...
Source code in src/cellects/display/plot.py
plot_blob_directions(pixel_data, colony_centroids, boundaries=None, starting_time=None, ending_time=None, max_colony_number=None, selection_criteria='size')
Summary
Plot colony contours and movement arrows on a white canvas.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pixel_data
|
ndarray or array-like
Array of shape (N, 4) containing |
required | |
colony_centroids
|
ndarray or array-like
Array of shape (M, 4) containing |
required | |
boundaries
|
list
|
list, optional
|
None
|
starting_time
|
int
|
int, optional
Only data with |
None
|
ending_time
|
int
|
int, optional
Only data with |
None
|
max_colony_number
|
int
|
int, optional
Maximum number of colonies to visualise. If |
None
|
selection_criteria
|
str
|
str, optional
Method used to select colonies when |
'size'
|
Returns:
| Name | Type | Description |
|---|---|---|
canvas |
ndarray
|
RGB image (uint8) of shape |
Notes
- The function creates a white background and draws on it using
cv2and a customdraw_arrowhelper; make sure those dependencies are available. - Arrow head size and line thickness are automatically reduced for large numbers of colonies to keep the figure readable.
Source code in src/cellects/display/plot.py
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 348 349 350 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 424 425 426 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 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
plot_growth_features(y, time_step, growth_features, save_path=None)
Plot growth surface data with linear and exponential fits, and rupture markers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
NDArray
|
Array of surface area measurements. |
required |
time_step
|
float
|
Time interval (in minutes) between successive measurements. |
required |
growth_features
|
dict
|
Dictionary containing regression coefficients, fit intervals,
rupture information, and optional R‑squared values. Expected keys
include |
required |
save_path
|
optional
|
File path where the figure will be saved. If |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Notes
- The function uses Matplotlib to construct a figure with a reduced
right margin (
fig.subplots_adjust(right=0.85)) so that the custom legend can be placed inside the reserved space without being clipped. - The legend is anchored at a fixed figure coordinate
(.8, .5); this works well for typical figure sizes but may require adjustment for unusually wide or tall plots. - All numeric values displayed in the legend are rounded to two decimal places for readability.
Source code in src/cellects/display/plot.py
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 175 176 177 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 | |
plot_spider_binned(colony_centroids, num_intervals=12)
Plot a polar “spider” diagram of colony orientation frequencies.
The function computes the average direction of each colony, bins the
directions into num_intervals angular sectors, normalises the counts,
and visualises the distribution on a polar plot. A dashed line marks the
overall mean direction when it can be defined.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
colony_centroids
|
dict or iterable
|
Collection that |
required |
num_intervals
|
int
|
Number of angular bins to use for the histogram. Default is |
12
|
Returns:
| Type | Description |
|---|---|
None
|
The function creates a Matplotlib figure; it does not return a value. |
Notes
- The polar axis is set to a north‑up, clockwise convention
(
ax.set_theta_zero_location("N")andax.set_theta_direction(-1)). - Counts are normalised by the maximum bin count, so the radial axis always
spans
[0, 1]. - If no directions are available the function prints a message and exits early without raising an exception.
- The implementation assumes that
numpy(np) andmatplotlib.pyplot(plt) are already imported in the surrounding module.
Source code in src/cellects/display/plot.py
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 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 | |
superimposed_barplot(big_bars, small_bars, colors, y_label, x_label, big_bar_labels, small_bar_labels, big_bar_width, space_between_small_bars, plot_saving_location='', fig_size=None, adjust_big_bar_number_pos=-0.1, adjust_small_bar_number_pos=-0.1, adjust_legend_pos=(1.3, 0.6))
:param big_bars: a list of 3 lists: The first contain the height of each big bar. The second contain its 0.025 CI, and its 0.975 CI The third contain its 0.975 CI :param small_bars: a list of length of the number of big_bars. Each element contain k lists: k is the number of small bar within each big bar. Each k element contain 3 values: the height of the small bar, its 0.025 CI, and its 0.975 CI :param colors: :param labels: :return:
Source code in src/cellects/display/plot.py
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 674 675 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 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 | |