The rscopulas.plotting module provides three functions for visualizing fitted copula models. The base rscopulas package does not depend on matplotlib, so these functions are only available after you install the optional viz extra. If you call any plotting function without matplotlib installed, you will get a clear ImportError with installation instructions.

Installation

uv add "rscopulas[viz]"

If you use pip directly:

pip install "rscopulas[viz]"

Import

from rscopulas.plotting import plot_density, plot_scatter, plot_vine_structure

plot_density

Plot a filled contour map of the bivariate copula density over the unit square [0, 1]². This function only supports models with dim == 2.

plot_density(
    model,
    *,
    ax=None,
    grid_size=100,
    levels=10,
    clip_eps=1e-12,
    cmap="viridis",
)
model
Anyrequired

A fitted copula model with a dim property equal to 2 and a log_pdf(data, *, clip_eps) method. Any rscopulas model with dim == 2 satisfies this interface.

Parameter
ax
matplotlib.axes.Axes | Nonedefault: None

A matplotlib Axes object to draw on. If None, a new figure and axes are created automatically.

Parameter
grid_size
intdefault: 100

Number of points per axis in the evaluation grid. Larger values produce smoother contours at the cost of more computation.

Parameter
levels
intdefault: 10

Number of filled contour levels. The contour overlay uses half this value.

Parameter
clip_eps
floatdefault: 1e-12

Boundary clipping passed to log_pdf to avoid evaluation at exact 0 or 1.

Parameter
cmap
strdefault: "viridis"

A matplotlib colormap name for the filled contours.

Parameter
return
matplotlib.axes.Axes

The axes object, so you can further customize or save the figure.

Response

Example

import numpy as np
from rscopulas import GaussianCopula
from rscopulas.plotting import plot_density
import matplotlib.pyplot as plt

corr = np.array([[1.0, 0.7], [0.7, 1.0]])
model = GaussianCopula.from_params(corr)

ax = plot_density(model, grid_size=80, cmap="plasma")
plt.savefig("gaussian_density.png", dpi=150, bbox_inches="tight")
plt.show()

plot_scatter

Plot pseudo-observations as a scatter plot. You can pass either an existing sample array or a model to draw samples from.

plot_scatter(
    *,
    sample=None,
    model=None,
    n=500,
    seed=None,
    ax=None,
    alpha=0.4,
    s=12,
    dims=(0, 1),
)
Warning

You must pass exactly one of sample or model. Passing both or neither raises a ValueError.

sample
ArrayLike | Nonedefault: None

A 2-D array of pseudo-observations to plot directly. Mutually exclusive with model.

Parameter
model
Any | Nonedefault: None

A fitted copula model with a sample(n, *, seed) method. The function draws n samples from the model before plotting. Mutually exclusive with sample.

Parameter
n
intdefault: 500

Number of samples to draw when model is provided.

Parameter
seed
int | Nonedefault: None

Random seed for reproducibility when sampling from model.

Parameter
ax
matplotlib.axes.Axes | Nonedefault: None

Axes to draw on. A new figure is created if None.

Parameter
alpha
floatdefault: 0.4

Point opacity. Lower values reduce overplotting for large samples.

Parameter
s
floatdefault: 12

Marker size in points squared, passed to matplotlib's scatter.

Parameter
dims
tuple[int, int]default: (0, 1)

Column indices to plot on the x and y axes. Useful for visualizing a 2-D slice of a higher-dimensional model.

Parameter
return
matplotlib.axes.Axes

The axes object.

Response

Example

import numpy as np
from rscopulas import ClaytonCopula
from rscopulas.plotting import plot_scatter

model = ClaytonCopula.from_params(dim=2, theta=3.0)
ax = plot_scatter(model=model, n=800, seed=1)
import numpy as np
from rscopulas.plotting import plot_scatter

rng = np.random.default_rng(0)
sample = rng.uniform(0.01, 0.99, size=(600, 4))

# Plot dimensions 1 and 3
ax = plot_scatter(sample=sample, dims=(1, 3), alpha=0.3)

plot_vine_structure

Visualize a fitted vine copula's structure matrix as a heatmap, with an optional annotation sidebar summarizing each tree level's edges and pair-copula families.

plot_vine_structure(vine_model, *, ax=None, annotate=True)
vine_model
VineCopularequired

A fitted VineCopula instance. The model must have structure_info and trees attributes.

Parameter
ax
matplotlib.axes.Axes | Nonedefault: None

Axes to draw on. A new figure is created if None.

Parameter
annotate
booldefault: True

When True, cell values are printed over the matrix heatmap and a monospace summary of each tree's edges is added to the right of the plot.

Parameter
return
matplotlib.axes.Axes

The axes object.

Response

Example

import numpy as np
from rscopulas import VineCopula
from rscopulas.plotting import plot_vine_structure
import matplotlib.pyplot as plt

rng = np.random.default_rng(0)
data = rng.uniform(0.01, 0.99, size=(500, 4))

result = VineCopula.fit_r(data, family_set=["gaussian", "clayton", "gumbel"])
vine = result.model

ax = plot_vine_structure(vine, annotate=True)
plt.tight_layout()
plt.savefig("vine_structure.png", dpi=150, bbox_inches="tight")
plt.show()

Missing viz extra

If you import from rscopulas.plotting without matplotlib installed, you will see:

ImportError: matplotlib is required for rscopulas plotting support.
Install it with `uv add 'rscopulas[viz]'` (in a uv project),
or `uv pip install 'rscopulas[viz]'` / `matplotlib`.

The error is raised lazily—only when you call a plotting function, not at import time.