BMPlot API Reference
This page provides API reference documentation for the BMPlot module which contains functions for plotting and visualizing BMTK network models and simulation results.
Connections Module
bmtool.bmplot.connections.is_notebook()
Detect if code is running in a Jupyter notebook environment.
Returns:
| Type | Description |
|---|---|
bool
|
True if running in a Jupyter notebook, False otherwise. |
Notes
This is used to determine whether to call plt.show() explicitly or rely on Jupyter's automatic display functionality.
Examples:
>>> if is_notebook():
... plt.show()
Source code in bmtool/bmplot/connections.py
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 | |
bmtool.bmplot.connections.total_connection_matrix(config, title=None, sources=None, targets=None, sids=None, tids=None, no_prepend_pop=False, synaptic_info='0', include_gap=True)
Generate a plot displaying total connections or other synaptic statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
str
|
Path to a BMTK simulation config file. |
required |
title
|
str
|
Title for the plot. If None, a default title will be used. |
None
|
sources
|
str
|
Comma-separated string of network names to use as sources. |
None
|
targets
|
str
|
Comma-separated string of network names to use as targets. |
None
|
sids
|
str
|
Comma-separated string of source node identifiers to filter. |
None
|
tids
|
str
|
Comma-separated string of target node identifiers to filter. |
None
|
no_prepend_pop
|
bool
|
If True, don't display population name before sid or tid in the plot. Default is False. |
False
|
synaptic_info
|
str
|
Type of information to display. Options: - '0': Total connections (default) - '1': Mean and standard deviation of connections - '2': All synapse .mod files used - '3': All synapse .json files used |
'0'
|
include_gap
|
bool
|
If True, include gap junctions and chemical synapses in the analysis. If False, only include chemical synapses. Default is True. |
True
|
Returns:
| Type | Description |
|---|---|
tuple of (Figure, Axes)
|
The matplotlib Figure and Axes objects for further customization or saving. |
Raises:
| Type | Description |
|---|---|
Exception
|
If config is not defined or sources/targets are not defined. |
Examples:
>>> total_connection_matrix(
... config='config.json',
... sources='PN',
... targets='LN',
... title='PN to LN Connections'
... )
Source code in bmtool/bmplot/connections.py
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 | |
bmtool.bmplot.connections.percent_connection_matrix(config, nodes=None, edges=None, title=None, sources=None, targets=None, sids=None, tids=None, no_prepend_pop=False, method='total', include_gap=True, return_dict=False)
Generates a plot showing the percent connectivity of a network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
str
|
Path to a BMTK simulation config file. |
required |
nodes
|
DataFrame
|
Pre-loaded node data. If None, will be loaded from config. |
None
|
edges
|
DataFrame
|
Pre-loaded edge data. If None, will be loaded from config. |
None
|
title
|
str
|
Title for the plot. If None, a default title will be used. |
None
|
sources
|
str
|
Comma-separated string of network name(s) to plot. |
None
|
targets
|
str
|
Comma-separated string of network name(s) to plot. |
None
|
sids
|
str
|
Comma-separated string of source node identifier(s) to filter. |
None
|
tids
|
str
|
Comma-separated string of target node identifier(s) to filter. |
None
|
no_prepend_pop
|
bool
|
If True, population name is not displayed before sid or tid in the plot. Default is False. |
False
|
method
|
str
|
Method for calculating percent connectivity. Options: 'total', 'uni', 'bi'. Default is 'total'. |
'total'
|
include_gap
|
bool
|
If True, include gap junctions in analysis. If False, only include chemical synapses. Default is True. |
True
|
return_dict
|
bool
|
If True, return connection information as a dictionary. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
Union[Tuple[Figure, Axes], Dict]
|
If return_dict=True, returns a dictionary of connection information. Otherwise, returns a tuple of (Figure, Axes) for further customization or saving. |
Raises:
| Type | Description |
|---|---|
Exception
|
If config is not defined or sources/targets are not defined. |
Examples:
>>> result = percent_connection_matrix(
... config='config.json',
... sources='PN',
... targets='LN',
... return_dict=True
... )
Source code in bmtool/bmplot/connections.py
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 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |
bmtool.bmplot.connections.probability_connection_matrix(config, nodes=None, edges=None, title=None, sources=None, targets=None, sids=None, tids=None, no_prepend_pop=False, dist_X=True, dist_Y=True, dist_Z=True, bins=8, line_plot=False, verbose=False, include_gap=True)
Generates probability graphs showing connectivity as a function of distance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
str
|
Path to a BMTK simulation config file. |
required |
nodes
|
DataFrame
|
Pre-loaded node data. If None, will be loaded from config. |
None
|
edges
|
DataFrame
|
Pre-loaded edge data. If None, will be loaded from config. |
None
|
title
|
str
|
Title for the plot. If None, a default title will be used. |
None
|
sources
|
str
|
Comma-separated string of network name(s) to plot. |
None
|
targets
|
str
|
Comma-separated string of network name(s) to plot. |
None
|
sids
|
str
|
Comma-separated string of source node identifier(s) to filter. |
None
|
tids
|
str
|
Comma-separated string of target node identifier(s) to filter. |
None
|
no_prepend_pop
|
bool
|
If True, population name is not displayed before sid or tid. Default is False. |
False
|
save_file
|
str
|
Path to save the plot. If None, plot is not saved. |
required |
dist_X
|
bool
|
If True, include X distance in calculations. Default is True. |
True
|
dist_Y
|
bool
|
If True, include Y distance in calculations. Default is True. |
True
|
dist_Z
|
bool
|
If True, include Z distance in calculations. Default is True. |
True
|
bins
|
int
|
Number of distance bins for the probability calculation. Default is 8. |
8
|
line_plot
|
bool
|
If True, plot lines instead of bars. Default is False. |
False
|
verbose
|
bool
|
If True, print debugging information. Default is False. |
False
|
include_gap
|
bool
|
If True, include gap junctions in analysis. Default is True. |
True
|
Returns:
| Type | Description |
|---|---|
None
|
|
Raises:
| Type | Description |
|---|---|
Exception
|
If config is not defined or sources/targets are not defined. |
Notes
This function needs model_template to be defined to work properly.
Source code in bmtool/bmplot/connections.py
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 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 | |
bmtool.bmplot.connections.convergence_connection_matrix(config, title=None, sources=None, targets=None, sids=None, tids=None, no_prepend_pop=False, convergence=True, method='mean+std', include_gap=True, return_dict=None)
Generates connection plot displaying synaptic convergence data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
str
|
Path to a BMTK simulation config file. |
required |
title
|
str
|
Title for the plot. If None, a default title will be used. |
None
|
sources
|
str
|
Comma-separated string of network name(s) to plot. |
None
|
targets
|
str
|
Comma-separated string of network name(s) to plot. |
None
|
sids
|
str
|
Comma-separated string of source node identifier(s) to filter. |
None
|
tids
|
str
|
Comma-separated string of target node identifier(s) to filter. |
None
|
no_prepend_pop
|
bool
|
If True, population name is not displayed before sid or tid. Default is False. |
False
|
save_file
|
str
|
Path to save the plot. If None, plot is not saved. |
required |
convergence
|
bool
|
If True, compute convergence; if False, compute divergence. Default is True. |
True
|
method
|
str
|
Statistical method for display. Options: 'mean', 'min', 'max', 'stdev', 'mean+std'. Default is 'mean+std'. |
'mean+std'
|
include_gap
|
bool
|
If True, include gap junctions in analysis. Default is True. |
True
|
return_dict
|
bool
|
If True, return connection information as a dictionary. Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
Union[Tuple[Figure, Axes], Dict, None]
|
If return_dict=True, returns a dictionary of connection information. Otherwise, returns a tuple of (Figure, Axes) for further customization or saving. |
Raises:
| Type | Description |
|---|---|
Exception
|
If config is not defined or sources/targets are not defined. |
Examples:
>>> result = convergence_connection_matrix(
... config='config.json',
... sources='PN',
... targets='LN',
... method='mean+std'
... )
Source code in bmtool/bmplot/connections.py
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 480 481 482 483 484 485 486 487 488 489 490 491 492 493 | |
bmtool.bmplot.connections.divergence_connection_matrix(config, title=None, sources=None, targets=None, sids=None, tids=None, no_prepend_pop=False, convergence=False, method='mean+std', include_gap=True, return_dict=None)
Generates connection plot displaying synaptic divergence data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
str
|
Path to a BMTK simulation config file. |
required |
title
|
str
|
Title for the plot. If None, a default title will be used. |
None
|
sources
|
str
|
Comma-separated string of network name(s) to plot. |
None
|
targets
|
str
|
Comma-separated string of network name(s) to plot. |
None
|
sids
|
str
|
Comma-separated string of source node identifier(s) to filter. |
None
|
tids
|
str
|
Comma-separated string of target node identifier(s) to filter. |
None
|
no_prepend_pop
|
bool
|
If True, population name is not displayed before sid or tid. Default is False. |
False
|
save_file
|
str
|
Path to save the plot. If None, plot is not saved. |
required |
convergence
|
bool
|
If True, compute convergence; if False, compute divergence. Default is False. |
False
|
method
|
str
|
Statistical method for display. Options: 'mean', 'min', 'max', 'stdev', 'mean+std'. Default is 'mean+std'. |
'mean+std'
|
include_gap
|
bool
|
If True, include gap junctions in analysis. Default is True. |
True
|
return_dict
|
bool
|
If True, return connection information as a dictionary. Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
Union[Tuple[Figure, Axes], Dict, None]
|
If return_dict=True, returns a dictionary of connection information. Otherwise, returns a tuple of (Figure, Axes) for further customization or saving. |
Raises:
| Type | Description |
|---|---|
Exception
|
If config is not defined or sources/targets are not defined. |
Examples:
>>> result = divergence_connection_matrix(
... config='config.json',
... sources='PN',
... targets='LN',
... method='mean+std'
... )
Source code in bmtool/bmplot/connections.py
496 497 498 499 500 501 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 | |
bmtool.bmplot.connections.gap_junction_matrix(config, title=None, sources=None, targets=None, sids=None, tids=None, no_prepend_pop=False, method='convergence')
Generates connection plot displaying gap junction data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
str
|
Path to a BMTK simulation config file. |
required |
title
|
str
|
Title for the plot. If None, a default title will be used. |
None
|
sources
|
str
|
Comma-separated string of network name(s) to plot. |
None
|
targets
|
str
|
Comma-separated string of network name(s) to plot. |
None
|
sids
|
str
|
Comma-separated string of source node identifier(s) to filter. |
None
|
tids
|
str
|
Comma-separated string of target node identifier(s) to filter. |
None
|
no_prepend_pop
|
bool
|
If True, population name is not displayed before sid or tid. Default is False. |
False
|
save_file
|
str
|
Path to save the plot. If None, plot is not saved. |
required |
method
|
str
|
Method for computing gap junction statistics. Options: 'convergence', 'percent'. Default is 'convergence'. |
'convergence'
|
Returns:
| Type | Description |
|---|---|
None
|
|
Raises:
| Type | Description |
|---|---|
Exception
|
If config is not defined, sources/targets are not defined, or method is invalid. |
Examples:
>>> gap_junction_matrix(
... config='config.json',
... sources='PN',
... targets='LN',
... method='convergence'
... )
Source code in bmtool/bmplot/connections.py
623 624 625 626 627 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 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 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 | |
bmtool.bmplot.connections.connection_histogram(config, nodes=None, edges=None, sources=None, targets=None, sids=None, tids=None, no_prepend_pop=True, synaptic_info='0', source_cell=None, target_cell=None, include_gap=True)
Generates histogram of the number of connections individual cells receive from another population.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
str
|
Path to a BMTK simulation config file. |
required |
nodes
|
DataFrame
|
Pre-loaded node data. If None, will be loaded from config. |
None
|
edges
|
DataFrame
|
Pre-loaded edge data. If None, will be loaded from config. |
None
|
sources
|
str
|
Comma-separated string of network name(s) to plot as sources. |
None
|
targets
|
str
|
Comma-separated string of network name(s) to plot as targets. |
None
|
sids
|
str
|
Comma-separated string of source node identifier(s) to filter by. |
None
|
tids
|
str
|
Comma-separated string of target node identifier(s) to filter by. |
None
|
no_prepend_pop
|
bool
|
If True, population name is not prepended to sid or tid. Default is True. |
True
|
synaptic_info
|
str
|
Type of synaptic information to display. Default is '0'. |
'0'
|
source_cell
|
str
|
Specific source cell type to plot connections from. |
None
|
target_cell
|
str
|
Specific target cell type to plot connections onto. |
None
|
include_gap
|
bool
|
If True, include gap junctions in analysis. Default is True. |
True
|
Returns:
| Type | Description |
|---|---|
tuple
|
(matplotlib.figure.Figure, matplotlib.axes.Axes) containing the histogram. |
Source code in bmtool/bmplot/connections.py
816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 | |
bmtool.bmplot.connections.connection_distance(config, sources, targets, source_cell_id, target_id_type, ignore_z=False)
Plots the 3D spatial distribution of target nodes relative to a source node and a histogram of distances from the source node to each target node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
str
|
Path to a BMTK simulation config file. |
required |
sources
|
str
|
Network name(s) to plot as sources. |
required |
targets
|
str
|
Network name(s) to plot as targets. |
required |
source_cell_id
|
int
|
ID of the source cell for calculating distances to target nodes. |
required |
target_id_type
|
str
|
String to filter target nodes based off the target_query. |
required |
ignore_z
|
bool
|
If True, ignore Z axis when calculating distance. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
tuple
|
Two tuples, each containing (matplotlib.figure.Figure, matplotlib.axes.Axes): - First tuple: 3D/2D scatter plot of node positions - Second tuple: Histogram of distances |
Examples:
>>> (fig1, ax1), (fig2, ax2) = connection_distance(
... config='config.json',
... sources='PN',
... targets='LN',
... source_cell_id=0,
... target_id_type='LN',
... ignore_z=False
... )
Source code in bmtool/bmplot/connections.py
965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 | |
bmtool.bmplot.connections.edge_histogram_matrix(config, sources=None, targets=None, sids=None, tids=None, no_prepend_pop=None, edge_property=None, time=None, time_compare=None, report=None, title=None)
Generates a matrix of histograms showing the distribution of edge properties between populations.
This function creates a grid of histograms where each cell represents the distribution of a specific edge property between source and target populations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
str
|
Path to a BMTK simulation config file. |
required |
sources
|
str
|
Comma-separated list of source network names. |
None
|
targets
|
str
|
Comma-separated list of target network names. |
None
|
sids
|
str
|
Comma-separated list of source node identifiers to filter by. |
None
|
tids
|
str
|
Comma-separated list of target node identifiers to filter by. |
None
|
no_prepend_pop
|
bool
|
If True, population names are not prepended to node identifiers. |
None
|
edge_property
|
str
|
The edge property to analyze (e.g., 'syn_weight', 'delay'). |
None
|
time
|
int
|
Time point to analyze from a time series report. |
None
|
time_compare
|
int
|
Second time point for comparison with time. |
None
|
report
|
str
|
Name of the report to analyze. |
None
|
title
|
str
|
Custom title for the plot. |
None
|
save_file
|
str
|
Path to save the generated plot. |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
(matplotlib.figure.Figure, matplotlib.axes.Axes) containing the histogram matrix. |
Examples:
>>> fig, axes = edge_histogram_matrix(
... config='config.json',
... sources='PN',
... targets='LN',
... edge_property='syn_weight'
... )
Source code in bmtool/bmplot/connections.py
1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 | |
bmtool.bmplot.connections.plot_connection_info(text, num, source_labels, target_labels, title, syn_info='0', return_dict=None)
Plot connection information as a heatmap with text annotations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
ndarray
|
2D array of text annotations for each cell. |
required |
num
|
ndarray
|
2D array of numerical values for the heatmap colors. |
required |
source_labels
|
list of str
|
Labels for source populations (rows). |
required |
target_labels
|
list of str
|
Labels for target populations (columns). |
required |
title
|
str
|
Title for the plot. |
required |
syn_info
|
str
|
Type of synaptic information being displayed. Options: '0', '1', '2', '3'. Default is '0'. |
'0'
|
save_file
|
str
|
Path to save the plot. If None, plot is not saved. |
required |
return_dict
|
bool
|
If True, return connection information as a dictionary. Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
Union[Tuple, Dict, None]
|
If return_dict=True, returns a dictionary of connection information. Otherwise, returns a tuple of (Figure, Axes), or None if just displaying. |
Notes
Handles missing source and target values by setting them to 0.
Source code in bmtool/bmplot/connections.py
1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 | |
bmtool.bmplot.connections.connector_percent_matrix(csv_path=None, exclude_strings=None, assemb_key=None, title='Percent connection matrix', pop_order=None)
Generates and plots a connection matrix based on connection probabilities from a CSV file.
This function visualizes percent connectivity while factoring in population distance and other parameters. It processes connection data by filtering 'Source' and 'Target' columns in the CSV and displays the percentage of connected pairs for each population combination in a matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
csv_path
|
str
|
Path to the CSV file containing connection data. The CSV should be an output from the
bmtool.connector classes, specifically generated by the |
None
|
exclude_strings
|
list of str
|
List of strings to exclude rows where 'Source' or 'Target' contain these strings. |
None
|
assemb_key
|
str
|
Key to identify and process assembly connections. |
None
|
title
|
str
|
Title for the generated plot. Default is 'Percent connection matrix'. |
'Percent connection matrix'
|
pop_order
|
list of str
|
List of population labels to specify the order for x- and y-ticks in the plot. |
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
(matplotlib.figure.Figure, matplotlib.axes.Axes) containing the heatmap. |
Examples:
>>> fig, ax = connector_percent_matrix(
... csv_path='connections.csv',
... exclude_strings=['Gap'],
... title='Network Connectivity'
... )
Source code in bmtool/bmplot/connections.py
1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 | |
bmtool.bmplot.connections.plot_3d_positions(config=None, sources=None, sid=None, title=None, subset=None)
Plots a 3D graph of all cells with x, y, z location.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
str
|
Path to a BMTK simulation config file. |
None
|
sources
|
str
|
Which network(s) to plot. If None or 'all', plots all networks. |
None
|
sid
|
str
|
Column name to group cell types (node grouping criteria). |
None
|
title
|
str
|
Plot title. Default is '3D positions'. |
None
|
subset
|
int
|
Take every Nth row. This makes plotting large networks easier to visualize. |
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
(matplotlib.figure.Figure, matplotlib.axes.Axes) containing the 3D plot. |
Examples:
>>> fig, ax = plot_3d_positions(
... config='config.json',
... sources='cortex',
... sid='node_type_id',
... title='3D Neuron Positions'
... )
Source code in bmtool/bmplot/connections.py
1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 | |
bmtool.bmplot.connections.plot_3d_cell_rotation(config=None, sources=None, sids=None, title=None, quiver_length=None, arrow_length_ratio=None, group=None, subset=None)
Plot 3D visualization of cell rotations with quiver arrows showing rotation orientations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
str
|
Path to a BMTK simulation config file. |
None
|
sources
|
list of str
|
Network names to plot. If None or contains 'all', plots all networks. |
None
|
sids
|
str
|
Comma-separated column names to group cell types. |
None
|
title
|
str
|
Plot title. Default is 'Cell rotations'. |
None
|
quiver_length
|
float
|
Length of the quiver arrows. If None, use matplotlib default. |
None
|
arrow_length_ratio
|
float
|
Ratio of arrow head size to quiver length. |
None
|
group
|
str
|
Comma-separated group names to include. If None, include all groups. |
None
|
subset
|
int
|
Take every Nth row. Useful for visualizing large networks. |
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
(matplotlib.figure.Figure, matplotlib.axes.Axes) containing the 3D plot. |
Examples:
>>> fig, ax = plot_3d_cell_rotation(
... config='config.json',
... sources=['cortex'],
... sids='node_type_id',
... title='Cell Rotation Vectors'
... )
Source code in bmtool/bmplot/connections.py
1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 | |
Spikes Module
bmtool.bmplot.spikes.raster(spikes_df=None, config=None, network_name=None, groupby='pop_name', sortby=None, ax=None, tstart=None, tstop=None, color_map=None, dot_size=0.3)
Plots a raster plot of neural spikes, with different colors for each population.
Parameters:
spikes_df : pd.DataFrame, optional
DataFrame containing spike data with columns 'timestamps', 'node_ids', and optional 'pop_name'.
config : str, optional
Path to the configuration file used to load node data.
network_name : str, optional
Specific network name to select from the configuration; if not provided, uses the first network.
groupby : str, optional
Column name to group spikes by for coloring. Default is 'pop_name'.
sortby : str, optional
Column name to sort node_ids within each group. If provided, nodes within each population will be sorted by this column.
ax : matplotlib.axes.Axes, optional
Axes on which to plot the raster; if None, a new figure and axes are created.
tstart : float, optional
Start time for filtering spikes; only spikes with timestamps greater than tstart will be plotted.
tstop : float, optional
Stop time for filtering spikes; only spikes with timestamps less than tstop will be plotted.
color_map : dict, optional
Dictionary specifying colors for each population. Keys should be population names, and values should be color values.
dot_size: float, optional
Size of the dot to display on the scatterplot
Returns:
matplotlib.axes.Axes Axes with the raster plot.
Notes:
- If
configis provided, the function merges population names from the node data withspikes_df. - Each unique population from groupby in
spikes_dfwill be represented by a different color ifcolor_mapis not specified. - If
color_mapis provided, it should contain colors for all uniquepop_namevalues inspikes_df.
Source code in bmtool/bmplot/spikes.py
14 15 16 17 18 19 20 21 22 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 | |
bmtool.bmplot.spikes.plot_firing_rate_pop_stats(firing_stats, groupby, ax=None, color_map=None)
Plots a bar graph of mean firing rates with error bars (standard deviation).
Parameters:
firing_stats : pd.DataFrame Dataframe containing 'firing_rate_mean' and 'firing_rate_std'. groupby : str or list of str Column(s) used for grouping. ax : matplotlib.axes.Axes, optional Axes on which to plot the bar chart; if None, a new figure and axes are created. color_map : dict, optional Dictionary specifying colors for each group. Keys should be group names, and values should be color values.
Returns:
matplotlib.axes.Axes Axes with the bar plot.
Source code in bmtool/bmplot/spikes.py
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 | |
bmtool.bmplot.spikes.plot_firing_rate_distribution(individual_stats, groupby, ax=None, color_map=None, plot_type='box', swarm_alpha=0.6, logscale=False)
Plots a distribution of individual firing rates using one or more plot types (box plot, violin plot, or swarm plot), overlaying them on top of each other.
Parameters:
individual_stats : pd.DataFrame Dataframe containing individual firing rates and corresponding group labels. groupby : str or list of str Column(s) used for grouping. ax : matplotlib.axes.Axes, optional Axes on which to plot the graph; if None, a new figure and axes are created. color_map : dict, optional Dictionary specifying colors for each group. Keys should be group names, and values should be color values. plot_type : str or list of str, optional List of plot types to generate. Options: "box", "violin", "swarm". Default is "box". swarm_alpha : float, optional Transparency of swarm plot points. Default is 0.6. logscale : bool, optional If True, use logarithmic scale for the y-axis (default is False).
Returns:
matplotlib.axes.Axes Axes with the selected plot type(s) overlayed.
Source code in bmtool/bmplot/spikes.py
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 348 349 350 351 | |
Entrainment Module
bmtool.bmplot.entrainment.plot_spike_power_correlation(spike_df, lfp_data, fs, pop_names, filter_method='wavelet', bandwidth=2.0, lowcut=None, highcut=None, freq_range=(10, 100), freq_step=5, type_name='raw', figsize=(12, 8))
Calculate and plot spike rate-LFP power correlation across frequencies for full signal.
Analyzes the relationship between population spike rates and LFP power across a range of frequencies, using Spearman correlation for the entire signal duration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spike_df
|
DataFrame
|
DataFrame containing spike data with columns 'timestamps', 'node_ids', and 'pop_name'. |
required |
lfp_data
|
DataArray
|
LFP data with time dimension. |
required |
fs
|
float
|
Sampling frequency in Hz. |
required |
pop_names
|
List[str]
|
List of population names to analyze. |
required |
filter_method
|
str
|
Filtering method: 'wavelet' or 'butter' (default: 'wavelet'). |
'wavelet'
|
bandwidth
|
float
|
Bandwidth parameter for wavelet filter (default: 2.0). |
2.0
|
lowcut
|
float
|
Lower frequency bound (Hz) for butterworth filter. Required if filter_method='butter'. |
None
|
highcut
|
float
|
Upper frequency bound (Hz) for butterworth filter. Required if filter_method='butter'. |
None
|
freq_range
|
Tuple[float, float]
|
Min and max frequency to analyze in Hz (default: (10, 100)). |
(10, 100)
|
freq_step
|
float
|
Step size for frequency analysis in Hz (default: 5). |
5
|
type_name
|
str
|
Which type of spike rate to use (default: 'raw'). |
'raw'
|
figsize
|
Tuple[float, float]
|
Figure size (width, height) in inches (default: (12, 8)). |
(12, 8)
|
Returns:
| Type | Description |
|---|---|
Figure
|
Figure containing the correlation plot. |
Notes
- Uses Spearman correlation (rank-based, robust to outliers).
- Pre-computes LFP power at all frequencies for efficiency.
Examples:
>>> fig = plot_spike_power_correlation(
... spike_df=spike_df,
... lfp_data=lfp,
... fs=400,
... pop_names=['PV', 'SST'],
... freq_range=(10, 100),
... freq_step=5
... )
Source code in bmtool/bmplot/entrainment.py
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 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
LFP Module
bmtool.bmplot.lfp.plot_spectrogram(sxx_xarray, remove_aperiodic=None, log_power=False, plt_range=None, clr_freq_range=None, pad=0.03, ax=None, vmin=None, vmax=None)
Plot a power spectrogram with optional aperiodic removal and frequency-based coloring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sxx_xarray
|
array - like
|
Spectrogram data as an xarray DataArray with PSD values. |
required |
remove_aperiodic
|
optional
|
FOOOF model object for aperiodic subtraction. If None, raw spectrum is displayed. |
None
|
log_power
|
bool or str
|
If True or 'dB', convert power to log scale. Default is False. |
False
|
plt_range
|
tuple of float
|
Frequency range to display as (f_min, f_max). If None, displays full range. |
None
|
clr_freq_range
|
tuple of float
|
Frequency range to use for determining color limits. If None, uses full range. |
None
|
pad
|
float
|
Padding for colorbar. Default is 0.03. |
0.03
|
ax
|
Axes
|
Axes to plot on. If None, creates a new figure and axes. |
None
|
vmin
|
float
|
Minimum value for colorbar scaling. If None, computed from data. |
None
|
vmax
|
float
|
Maximum value for colorbar scaling. If None, computed from data. |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The figure object containing the spectrogram. |
Examples:
>>> fig = plot_spectrogram(
... sxx_xarray, log_power='dB',
... plt_range=(10, 100), clr_freq_range=(20, 50)
... )
Source code in bmtool/bmplot/lfp.py
11 12 13 14 15 16 17 18 19 20 21 22 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 | |