class GridMatrix
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.
/tf/active/vicechatdev/patches/spaces.py
1873 - 1889
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 containerdata: 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
numpyparamitertoolsnumbersfunctoolscollectionscontextlibtypesinspect
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
OptionalUsage 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
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class GridSpace 71.1% similar
-
class HoloMap 55.4% similar
-
function expand_grid_coords 52.9% similar
-
class DynamicMap 41.9% similar
-
function create_grouped_correlation_plot 39.7% similar