Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Fixed
- Fix `plotly.colors.sample_colorscale` raising opaque errors for sample points outside the colorscale's range; out-of-range points now raise a clear `PlotlyError`.

## [7.2.0] - 2026-11-24

Expand Down
5 changes: 5 additions & 0 deletions _plotly_utils/colors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,11 @@ def sample_colorscale(colorscale, samplepoints, low=0.0, high=1.0, colortype="rg
]
elif isinstance(samplepoints, float):
samplepoints = [samplepoints]
else:
samplepoints = list(samplepoints)

if any(point < 0 or point > 1 for point in samplepoints):
raise exceptions.PlotlyError("Samplepoints must be between 0 and 1.")

sampled_colors = []
for point in samplepoints:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_plotly_utils/colors/test_sample_colorscale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest

from plotly.colors import sample_colorscale
from plotly.exceptions import PlotlyError


@pytest.mark.parametrize("point", [-0.25, 1.25])
def test_sample_colorscale_rejects_out_of_range_points(point):
colorscale = [[0.0, "rgb(0, 0, 0)"], [1.0, "rgb(255, 255, 255)"]]

with pytest.raises(PlotlyError, match="must be between 0 and 1"):
sample_colorscale(colorscale, [point])