Skip to content

error in plot_alignment #912

@miniufo

Description

@miniufo

Describe the bug
When I tried to understand the kwarg alignment using the plot_alignment, it raises an strange error.

Code Sample

Below is the example codes. When slicing with 8 values of both init and time, it raises an error ValueError: The truth value of a CFTimeIndex is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). Change to 10 is fine in this case.

from climpred import HindcastEnsemble
from climpred.tutorial import load_dataset
import matplotlib.pyplot as plt
import numpy as np
import xarray as xr

hind = load_dataset("CESM-DP-SST")["SST"].isel(init=slice(8))
verif = load_dataset("ERSST")["SST"].isel(time=slice(8))

hindcast = HindcastEnsemble(hind)
hindcast = hindcast.add_observations(verif)

print(hind.init.values)
print(verif.time.values)
hindcast.plot_alignment(edgecolor="w", figsize=(15, 5))

Expected behavior
No exception is raised when slicing with 8.

Output of climpred.show_versions()

Details INSTALLED VERSIONS ------------------ commit: None python: 3.13.7 | packaged by Anaconda, Inc. | (main, Sep 9 2025, 19:59:03) [GCC 11.2.0] python-bits: 64 OS: Linux OS-release: 6.14.0-29-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: zh_CN.UTF-8 LOCALE: zh_CN.UTF-8

climpred: 2.4.0
xarray: 2025.4.0
pandas: 2.3.2
numpy: 2.2.5
scipy: 1.16.1
cftime: 1.6.4
netcdf4: None
nc_time_axis: 1.4.1
matplotlib: 3.10.6
cf_xarray: 0.10.9
xclim: 0.58.1
dask: 2025.9.0
distributed: 2025.9.0
setuptools: 72.1.0
pip: 25.2
conda: None
IPython: 9.1.0
sphinx: None
None

Screenshots

Image

Additional context
No

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions