-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into inspector_tests
- Loading branch information
Showing
10 changed files
with
225 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,7 @@ | |
"def add(x, y):\n", | ||
" return x + y\n", | ||
"\n", | ||
"\n", | ||
"c = pp.Node(add, a, b)\n", | ||
"c()" | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
superplot | ||
inspector | ||
scatter3d | ||
xyplot | ||
``` | ||
|
||
## Core | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp) | ||
|
||
from typing import Union | ||
|
||
import scipp as sc | ||
from numpy import ndarray | ||
|
||
from ..core import Node | ||
from ..graphics import figure1d | ||
from .common import to_variable | ||
|
||
|
||
def _make_data_array(x: sc.Variable, y: sc.Variable) -> sc.DataArray: | ||
""" | ||
Make a data array from the supplied variables, using ``x`` as the coordinate and | ||
``y`` as the data. | ||
Parameters | ||
---------- | ||
x: | ||
The variable to use as the coordinate. | ||
y: | ||
The variable to use as the data. | ||
""" | ||
return sc.DataArray(data=y, coords={x.dim: x}) | ||
|
||
|
||
def xyplot( | ||
x: Union[sc.Variable, ndarray, list, Node], | ||
y: Union[sc.Variable, ndarray, list, Node], | ||
**kwargs, | ||
): | ||
""" | ||
Make a one-dimensional plot of one variable ``y`` as a function of another ``x``. | ||
.. versionadded:: <TODO:VERSION> | ||
Parameters | ||
---------- | ||
x: | ||
The variable to use as the coordinates for the horizontal axis. | ||
Must be one-dimensional. | ||
y: | ||
The variable to use as the data for the vertical axis. Must be one-dimensional. | ||
**kwargs: | ||
See :py:func:`plopp.plot`. | ||
""" | ||
x = Node(to_variable, x) | ||
y = Node(to_variable, y) | ||
dim = x().dim | ||
if dim != y().dim: | ||
raise sc.DimensionError("Dimensions of x and y must match") | ||
return figure1d(Node(_make_data_array, x=x, y=y), **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp) | ||
|
||
import numpy as np | ||
import pytest | ||
import scipp as sc | ||
|
||
import plopp as pp | ||
|
||
|
||
def test_xyplot_variable(): | ||
x = sc.arange('time', 20.0, unit='s') | ||
y = sc.arange('time', 100.0, 120.0, unit='K') | ||
fig = pp.xyplot(x, y) | ||
assert fig.canvas.xlabel == 'time [s]' | ||
assert fig.canvas.ylabel == '[K]' | ||
|
||
|
||
def test_xyplot_ndarray(): | ||
N = 50 | ||
x = np.arange(float(N)) | ||
y = np.linspace(-44.0, 44.0, N) | ||
pp.xyplot(x, y) | ||
|
||
|
||
def test_xyplot_list(): | ||
x = [1, 2, 3, 4, 5] | ||
y = [6, 7, 2, 0, 1] | ||
pp.xyplot(x, y) | ||
|
||
|
||
def test_xyplot_different_dims_raises(): | ||
x = sc.arange('x', 20.0, unit='s') | ||
y = sc.arange('y', 100.0, 120.0, unit='K') | ||
with pytest.raises(sc.DimensionError, match='Dimensions of x and y must match'): | ||
pp.xyplot(x, y) | ||
|
||
|
||
def test_xyplot_data_array_raises(): | ||
x = sc.arange('x', 20.0, unit='s') | ||
y = pp.data.data1d() | ||
with pytest.raises(TypeError, match='Cannot convert input of type'): | ||
pp.xyplot(x, y) | ||
with pytest.raises(TypeError, match='Cannot convert input of type'): | ||
pp.xyplot(y, x) | ||
|
||
|
||
def test_xyplot_2d_variable_raises(): | ||
x = sc.arange('x', 50.0, unit='s') | ||
y = pp.data.data2d().data | ||
with pytest.raises(sc.DimensionError, match='Expected 1 dimensions, got 2'): | ||
pp.xyplot(x, y) | ||
with pytest.raises(sc.DimensionError, match='Expected 1 dimensions, got 2'): | ||
pp.xyplot(y, x) | ||
|
||
|
||
def test_xyplot_variable_kwargs(): | ||
x = sc.arange('time', 20.0, unit='s') | ||
y = sc.arange('time', 100.0, 120.0, unit='K') | ||
fig = pp.xyplot(x, y, color='red', vmin=102.0, vmax=115.0) | ||
assert np.allclose(fig.canvas.yrange, [102.0, 115.0]) | ||
line = list(fig.artists.values())[0] | ||
assert line.color == 'red' | ||
|
||
|
||
def test_xyplot_bin_edges(): | ||
x = sc.arange('time', 21.0, unit='s') | ||
y = sc.arange('time', 100.0, 120.0, unit='K') | ||
fig = pp.xyplot(x, y) | ||
line = list(fig.artists.values())[0] | ||
assert len(line._line.get_xdata()) == 21 | ||
|
||
|
||
def test_xyplot_from_nodes(): | ||
x = sc.arange('time', 20.0, unit='s') | ||
y = sc.arange('time', 100.0, 120.0, unit='K') | ||
pp.xyplot(pp.Node(x), y) | ||
pp.xyplot(x, pp.Node(y)) | ||
pp.xyplot(pp.Node(x), pp.Node(y)) |