Plot voltages for any group(s) of neurons. :param voltages: Contains voltage data by neuron layers. :param ims: Used for re-drawing the plots. :param axes: Used for re-drawing the plots. :param time: Plot voltages of neurons in given time range. Default is entire simula
(
voltages: Dict[str, torch.Tensor],
ims: Optional[List[AxesImage]] = None,
axes: Optional[List[Axes]] = None,
time: Tuple[int, int] = None,
n_neurons: Optional[Dict[str, Tuple[int, int]]] = None,
cmap: Optional[str] = "jet",
plot_type: str = "color",
thresholds: Dict[str, torch.Tensor] = None,
figsize: Tuple[float, float] = (8.0, 4.5),
)
| 642 | |
| 643 | |
| 644 | def plot_voltages( |
| 645 | voltages: Dict[str, torch.Tensor], |
| 646 | ims: Optional[List[AxesImage]] = None, |
| 647 | axes: Optional[List[Axes]] = None, |
| 648 | time: Tuple[int, int] = None, |
| 649 | n_neurons: Optional[Dict[str, Tuple[int, int]]] = None, |
| 650 | cmap: Optional[str] = "jet", |
| 651 | plot_type: str = "color", |
| 652 | thresholds: Dict[str, torch.Tensor] = None, |
| 653 | figsize: Tuple[float, float] = (8.0, 4.5), |
| 654 | ) -> Tuple[List[AxesImage], List[Axes]]: |
| 655 | # language=rst |
| 656 | """ |
| 657 | Plot voltages for any group(s) of neurons. |
| 658 | |
| 659 | :param voltages: Contains voltage data by neuron layers. |
| 660 | :param ims: Used for re-drawing the plots. |
| 661 | :param axes: Used for re-drawing the plots. |
| 662 | :param time: Plot voltages of neurons in given time range. Default is entire |
| 663 | simulation time. |
| 664 | :param n_neurons: Plot voltages of neurons in given range of neurons. Default is all |
| 665 | neurons. |
| 666 | :param cmap: Matplotlib colormap to use. |
| 667 | :param figsize: Horizontal, vertical figure size in inches. |
| 668 | :param plot_type: The way how to draw graph. 'color' for pcolormesh, 'line' for |
| 669 | curved lines. |
| 670 | :param thresholds: Thresholds of the neurons in each layer. |
| 671 | :return: ``ims, axes``: Used for re-drawing the plots. |
| 672 | """ |
| 673 | n_subplots = len(voltages.keys()) |
| 674 | |
| 675 | # for key in voltages.keys(): |
| 676 | # voltages[key] = voltages[key].view(-1, voltages[key].size(-1)) |
| 677 | voltages = {k: v.view(v.size(0), -1) for (k, v) in voltages.items()} |
| 678 | |
| 679 | if time is None: |
| 680 | for key in voltages.keys(): |
| 681 | time = (0, voltages[key].size(0)) |
| 682 | break |
| 683 | |
| 684 | if n_neurons is None: |
| 685 | n_neurons = {} |
| 686 | |
| 687 | for key, val in voltages.items(): |
| 688 | if key not in n_neurons.keys(): |
| 689 | n_neurons[key] = (0, val.size(1)) |
| 690 | |
| 691 | if not ims: |
| 692 | fig, axes = plt.subplots(n_subplots, 1, figsize=figsize) |
| 693 | ims = [] |
| 694 | if n_subplots == 1: # Plotting only one image |
| 695 | for v in voltages.items(): |
| 696 | if plot_type == "line": |
| 697 | ims.append( |
| 698 | axes.plot( |
| 699 | v[1] |
| 700 | .detach() |
| 701 | .clone() |
no test coverage detected