myoverse.datatypes.EMGData.plot_grid_layout#
- EMGData.plot_grid_layout(grid_idx=0, show_indices=True, cmap=None, figsize=None, title=None, colorbar=True, grid_color='black', grid_alpha=0.7, text_color='white', text_fontsize=10, text_fontweight='bold', highlight_electrodes=None, highlight_color='red', save_path=None, dpi=150, return_fig=False, ax=None, autoshow=True)[source]#
Plots the 2D layout of a specific electrode grid with enhanced visualization.
- Parameters:
grid_idx (int, optional) – The index of the grid to plot. Default is 0.
show_indices (bool, optional) – Whether to show the electrode indices in the plot. Default is True.
cmap (Optional[plt.cm.ScalarMappable], optional) – Custom colormap to use for visualization. If None, a default viridis colormap is used.
figsize (Optional[Tuple[float, float]], optional) – Custom figure size as (width, height) in inches. If None, size is calculated based on grid dimensions. Ignored if an existing axes object is provided.
title (Optional[str], optional) – Custom title for the plot. If None, a default title showing grid dimensions is used.
colorbar (bool, optional) – Whether to show a colorbar. Default is True.
grid_color (str, optional) – Color of the grid lines. Default is “black”.
grid_alpha (float, optional) – Transparency of grid lines (0-1). Default is 0.7.
text_color (str, optional) – Color of the electrode indices text. Default is “white”.
text_fontsize (int, optional) – Font size for electrode indices. Default is 10.
text_fontweight (str, optional) – Font weight for electrode indices. Default is “bold”.
highlight_electrodes (Optional[List[int]], optional) – List of electrode indices to highlight. Default is None.
highlight_color (str, optional) – Color to use for highlighting electrodes. Default is “red”.
save_path (Optional[str], optional) – Path to save the figure. If None, figure is not saved. Default is None.
dpi (int, optional) – DPI for saved figure. Default is 150.
return_fig (bool, optional) – Whether to return the figure and axes. Default is False.
ax (Optional[plt.Axes], optional) – Existing axes object to plot on. If None, a new figure and axes will be created.
autoshow (bool, optional) – Whether to automatically show the figure. Default is True. Set to False when plotting multiple grids on the same figure.
- Returns:
Figure and axes objects if return_fig is True.
- Return type:
Optional[Tuple[plt.Figure, plt.Axes]]
- Raises:
ValueError – If grid_layouts is not available or the grid_idx is out of range.
Examples
>>> import numpy as np >>> from myoverse.datatypes import EMGData, create_grid_layout >>> >>> # Create sample EMG data (64 channels, 1000 samples) >>> emg_data = np.random.randn(64, 1000) >>> >>> # Create an 8×8 grid with some missing electrodes >>> grid = create_grid_layout(8, 8, 64, fill_pattern='row', ... missing_indices=[(7, 7), (0, 0)]) >>> >>> emg = EMGData(emg_data, 2000, grid_layouts=[grid]) >>> >>> # Basic visualization >>> emg.plot_grid_layout(0) >>> >>> # Advanced visualization >>> emg.plot_grid_layout( ... 0, ... figsize=(10, 10), ... colorbar=True, ... highlight_electrodes=[10, 20, 30], ... grid_alpha=0.5 ... ) >>> >>> # Multiple grids in one figure >>> import matplotlib.pyplot as plt >>> fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 6)) >>> emg.plot_grid_layout(0, title="Grid 1", ax=ax1, autoshow=False) >>> emg.plot_grid_layout(1, title="Grid 2", ax=ax2, autoshow=False) >>> plt.tight_layout() >>> plt.show()