🔍 Code Extractor

class GridMatrix

Maturity: 53

GridMatrix is a container class for heterogeneous Element types arranged in a grid layout where axes don't represent coordinate space but are used to plot various dimensions against each other.

File:
/tf/active/vicechatdev/patches/spaces.py
Lines:
1873 - 1889
Complexity:
moderate

Purpose

GridMatrix extends GridSpace to provide a specialized container for displaying multiple dimensions of data plotted against each other in a matrix layout. Unlike GridSpace, the axes don't represent actual coordinate space. It's typically constructed using the gridmatrix operation to create visualizations where each dimension in an Element is plotted against every other dimension, useful for exploratory data analysis and correlation visualization.

Source Code

class GridMatrix(GridSpace):
    """
    GridMatrix is container type for heterogeneous Element types
    laid out in a grid. Unlike a GridSpace the axes of the Grid
    must not represent an actual coordinate space, but may be used
    to plot various dimensions against each other. The GridMatrix
    is usually constructed using the gridmatrix operation, which
    will generate a GridMatrix plotting each dimension in an
    Element against each other.
    """


    def _item_check(self, dim_vals, data):
        if not traversal.uniform(NdMapping([(0, self), (1, data)])):
            raise ValueError("HoloMaps dimensions must be consistent in %s." %
                             type(self).__name__)
        NdMapping._item_check(self, dim_vals, data)

Parameters

Name Type Default Kind
bases GridSpace -

Parameter Details

__init__: Inherits constructor from GridSpace parent class. Accepts parameters defined by GridSpace and its parent classes (NdMapping, UniformNdMapping). Typically includes data items, key dimensions (kdims), value dimensions (vdims), and other container configuration options.

Return Value

Instantiation returns a GridMatrix object that behaves as a container for heterogeneous Element types. The _item_check method returns None but raises ValueError if validation fails. The class provides access to grid-arranged elements through inherited methods from GridSpace and NdMapping.

Class Interface

Methods

_item_check(self, dim_vals, data) -> None

Purpose: Validates that items being added to the GridMatrix maintain dimensional uniformity across the container

Parameters:

  • dim_vals: Dimension values (keys) for the item being added to the container
  • data: The data element being added to the GridMatrix

Returns: None - raises ValueError if validation fails, otherwise completes silently

Attributes

Name Type Description Scope
Inherited from GridSpace and NdMapping Various GridMatrix inherits all attributes from GridSpace parent class including kdims (key dimensions), vdims (value dimensions), data storage, and grid layout configuration. Specific attributes depend on the parent class implementation. instance

Dependencies

  • numpy
  • param
  • itertools
  • numbers
  • functools
  • collections
  • contextlib
  • types
  • inspect

Required Imports

import numpy as np
import param
import itertools
from numbers import Number
from itertools import groupby
from functools import partial
from collections import defaultdict
from contextlib import contextmanager
from types import FunctionType
from inspect import FullArgSpec

Conditional/Optional Imports

These imports are only needed under specific conditions:

from inspect import ArgSpec as FullArgSpec

Condition: fallback when FullArgSpec is not available in older Python versions

Optional

Usage Example

# Typically created using gridmatrix operation
import holoviews as hv
import pandas as pd
import numpy as np

# Create sample data
df = pd.DataFrame({
    'x': np.random.randn(100),
    'y': np.random.randn(100),
    'z': np.random.randn(100)
})

# Create GridMatrix using gridmatrix operation
from holoviews.operation import gridmatrix
ds = hv.Dataset(df)
grid = gridmatrix(ds)

# Access elements in the grid
# grid[x_dim, y_dim] returns the plot at that position

# The GridMatrix validates that all contained elements have uniform dimensions
# and maintains consistency across the grid structure

Best Practices

  • Use the gridmatrix operation to construct GridMatrix instances rather than manual instantiation
  • Ensure all elements added to the GridMatrix have uniform dimensions to avoid validation errors
  • GridMatrix is designed for plotting dimensions against each other, not for coordinate-based spatial layouts
  • The _item_check method enforces dimension uniformity - all HoloMaps must have consistent dimensions
  • GridMatrix inherits from GridSpace, so it supports all GridSpace operations and indexing patterns
  • When adding items, the traversal.uniform check ensures consistency across the entire structure
  • Use for exploratory data analysis to visualize relationships between multiple dimensions simultaneously

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class GridSpace 71.1% similar

    GridSpace is a container class for organizing elements in a 1D or 2D grid structure with floating-point keys, ensuring all contained elements are of the same type.

    From: /tf/active/vicechatdev/patches/spaces.py
  • class HoloMap 55.4% similar

    HoloMap is an n-dimensional mapping container that stores viewable elements or overlays indexed by tuple keys along declared key dimensions, enabling interactive exploration through widgets.

    From: /tf/active/vicechatdev/patches/spaces.py
  • function expand_grid_coords 52.9% similar

    Expands coordinates along a specified dimension of a gridded dataset into an N-dimensional array that matches the full dimensionality of the dataset.

    From: /tf/active/vicechatdev/patches/util.py
  • class DynamicMap 41.9% similar

    A DynamicMap is a type of HoloMap where the elements are dynamically generated by a callable. The callable is invoked with values associated with the key dimensions or with values supplied by stream parameters.

    From: /tf/active/vicechatdev/patches/spaces.py
  • function create_grouped_correlation_plot 39.7% similar

    Creates and saves a dual-panel heatmap visualization showing correlation matrices grouped by treatment and challenge regimen variables.

    From: /tf/active/vicechatdev/vice_ai/smartstat_scripts/5a059cb7-3903-4020-8519-14198d1f39c9/analysis_1.py
← Back to Browse