Inconsistent behavior for `hue` between scatter and line
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
What happened?
The behavior of hue results in different colors ds.plot.scatter vs ds.plot.line
Both docstrings describe hue as:
hue (Hashable, optional) – Dimension or coordinate for which you want multiple lines plotted. If plotting against a 2D coordinate, hue must be a dimension.
Which they both faithfully do, but despite being named hue they have inconsistent color behavior.
What did you expect to happen?
consistent behavior where each line that corresponds to the same hue has the same color (like in scatter). What I actually got is:
Minimal Complete Verifiable Example
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "xarray[complete]==2025.10.0"
# ]
# ///
import matplotlib.pyplot as plt
import xarray as xr
xr.show_versions()
# your reproducer code ...
import numpy as np
T = np.linspace(0, 2 * np.pi, 50)
data = np.sin(np.ones([6, 50]) * T)
# data = np.sin(T)
# data =data[None, :], (6,50)
for i in range(6):
data[i, :] += i
categories = ["a", "a", "b", "b", "c", "c"]
da = xr.DataArray(data, dims=("category", "T"), coords={"category": categories, "T": T})
fig, axs = plt.subplots(1, 2, figsize=(10, 4))
da.plot.scatter(hue="category", ax=axs[0])
da.plot.line(hue="category", ax=axs[1])
axs[0].set_title("scatter")
axs[1].set_title("line")
plt.show()
Steps to reproduce
uv run above script
MVCE confirmation
- Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
- Complete example — the example is self-contained, including all data and the text of any traceback.
- Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
- New issue — a search of GitHub Issues suggests this is not a duplicate.
- Recent environment — the issue occurs with the latest version of xarray and its dependencies.
Relevant log output
Anything else we need to know?
I think this is related to, but distinct from https://github.com/pydata/xarray/issues/10674
Environment
INSTALLED VERSIONS
commit: None
python: 3.13.0 (main, Oct 16 2024, 08:05:40) [Clang 18.1.8 ]
python-bits: 64
OS: Darwin
OS-release: 24.6.0
machine: arm64
processor: arm
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.14.6
libnetcdf: 4.9.3
xarray: 2025.9.2.dev1+geed12c498
pandas: 2.3.3
numpy: 2.3.5
scipy: 1.16.3
netCDF4: 1.7.3
pydap: 3.5.8
h5netcdf: 1.7.3
h5py: 3.15.1
zarr: 3.1.5
cftime: 1.6.5
nc_time_axis: 1.4.1
iris: None
bottleneck: 1.6.0
dask: 2025.11.0
distributed: 2025.11.0
matplotlib: 3.10.7
cartopy: 0.25.0
seaborn: 0.13.2
numbagg: 0.9.3
fsspec: 2025.12.0
cupy: None
pint: None
sparse: 0.17.0
flox: 0.10.7
numpy_groupies: 0.11.3
setuptools: None
pip: None
conda: None
pytest: None
mypy: None
IPython: None
sphinx: None
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided Python example and compare the colors produced by da.plot.scatter(hue="category") and da.plot.line(hue="category"). Trace the plotting entry points for scatter and line, then verify that lines sharing a hue use the same colors as scatter; add regression coverage for the reproduced case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- matplotlib, python
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100