Implementation:Sdv dev SDV Get Cardinality Plot
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Visualization, Relational_Data |
| Last Updated | 2026-02-14 00:00 GMT |
Overview
Wrapper for SDMetrics cardinality visualization, comparing parent-child relationship distributions in multi-table data within SDV workflows.
Description
The get_cardinality_plot function creates a Plotly figure comparing the cardinality distribution (child rows per parent) between real and synthetic multi-table data.
Usage
Call with multi-table real and synthetic data, specifying the parent-child relationship.
Code Reference
Source Location
- Repository: SDV
- File: sdv/evaluation/multi_table.py
- Lines: L134-174
Signature
def get_cardinality_plot(
real_data, synthetic_data, child_table_name, parent_table_name,
child_foreign_key, metadata, plot_type='bar'
):
"""Plot cardinality distribution of a parent-child relationship.
Args:
real_data (dict): Real multi-table data.
synthetic_data (dict): Synthetic multi-table data.
child_table_name (str): Child table name.
parent_table_name (str): Parent table name.
child_foreign_key (str): Foreign key column in child table.
metadata (Metadata): Multi-table metadata.
plot_type (str): 'bar' or 'distplot'. Defaults to 'bar'.
Returns:
plotly.graph_objects.Figure: Cardinality comparison plot.
"""
Import
from sdv.evaluation.multi_table import get_cardinality_plot
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| real_data | dict[str, pd.DataFrame] | Yes | Real multi-table data |
| synthetic_data | dict[str, pd.DataFrame] | Yes | Synthetic multi-table data |
| child_table_name | str | Yes | Child table in the relationship |
| parent_table_name | str | Yes | Parent table in the relationship |
| child_foreign_key | str | Yes | Foreign key column in child table |
| metadata | Metadata | Yes | Multi-table metadata |
| plot_type | str | No | 'bar' or 'distplot' (default: 'bar') |
Outputs
| Name | Type | Description |
|---|---|---|
| return value | plotly.graph_objects.Figure | Cardinality comparison plot |
Usage Examples
from sdv.evaluation.multi_table import get_cardinality_plot
fig = get_cardinality_plot(
real_data, synthetic_data,
child_table_name='guests',
parent_table_name='hotels',
child_foreign_key='hotel_id',
metadata=metadata,
)
fig.show()
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment