Skip to content
Merged
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
5 changes: 5 additions & 0 deletions src/plopp/plotting/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ def _maybe_to_variable(obj: Plottable | list) -> Plottable:
out = np.array(out)
if isinstance(out, np.ndarray):
dims = [f"axis-{i}" for i in range(len(out.shape))]
if np.issubdtype(out.dtype, np.unsignedinteger):
# This conversion is not completely without loss in the case of very large
# unsigned integers, but it is probably fine in most cases, and better than
# not plotting the data at all.
out = out.astype('int64')
out = sc.Variable(dims=dims, values=out)
return out

Expand Down
5 changes: 5 additions & 0 deletions tests/plotting/plot_1d_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def test_plot_variable():
pp.plot(sc.arange('x', 50.0))


@pytest.mark.parametrize("dtype", [np.uint8, np.uint16, np.uint32, np.uint64])
def test_plot_ndarray_uint(dtype):
pp.plot(np.arange(50, dtype=dtype))


def test_plot_data_array():
pp.plot(data_array(ndim=1))

Expand Down
5 changes: 5 additions & 0 deletions tests/plotting/plot_2d_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ def test_plot_ndarray_int():
pp.plot(np.arange(50).reshape(5, 10))


@pytest.mark.parametrize("dtype", [np.uint8, np.uint16, np.uint32, np.uint64])
def test_plot_ndarray_uint(dtype):
pp.plot(np.arange(50, dtype=dtype).reshape(5, 10))


def test_plot_variable():
pp.plot(variable(ndim=2))

Expand Down
Loading