Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/torchio/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import warnings
from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any

import numpy as np
import torch
Expand All @@ -24,6 +25,7 @@
if TYPE_CHECKING:
from matplotlib.colors import BoundaryNorm
from matplotlib.colors import ListedColormap
from matplotlib.figure import Figure


def import_mpl_plt():
Expand Down Expand Up @@ -80,10 +82,11 @@ def plot_volume(
reorient=True,
indices=None,
rgb=True,
savefig_kwargs: dict[str, Any] | None = None,
**imshow_kwargs,
):
) -> Figure | None:
_, plt = import_mpl_plt()
fig = None
fig: Figure | None = None
if axes is None:
fig, axes = plt.subplots(1, 3, figsize=figsize)

Expand Down Expand Up @@ -182,7 +185,9 @@ def plot_volume(
plt.suptitle(title)

if output_path is not None and fig is not None:
fig.savefig(output_path)
if savefig_kwargs is None:
savefig_kwargs = {}
fig.savefig(output_path, **savefig_kwargs)
if show:
plt.show()
return fig
Expand Down
Loading