Skip to content

Commit 7c4bb8e

Browse files
authored
Merge pull request #324 from scipp/docs-tweaks
Small docs fixes
2 parents c95e375 + 8b5ea7c commit 7c4bb8e

File tree

8 files changed

+102
-17
lines changed

8 files changed

+102
-17
lines changed

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ filterwarnings = [
6262
'ignore:Passing unrecognized arguments to super:DeprecationWarning',
6363
'ignore:Jupyter is migrating its paths:DeprecationWarning',
6464
'ignore:setDaemon\(\) is deprecated, set the daemon attribute instead:DeprecationWarning',
65+
'ignore:TriCutTool is deprecated::',
66+
'ignore:Cut3dTool is deprecated::',
6567
]
6668

6769
[tool.bandit]

src/plopp/graphics/figure.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
33

4-
import warnings
54
from typing import Literal
65

76
from .. import backends
8-
from ..core.typing import VisibleDeprecationWarning
9-
10-
11-
def _warn_deprecated(func_name: str, new_func_name: str):
12-
warnings.warn(
13-
f'The function `{func_name}` is deprecated and will be removed in a future '
14-
f'version. Use `{new_func_name}` instead.',
15-
VisibleDeprecationWarning,
16-
stacklevel=2,
17-
)
7+
from ..utils import deprecated
188

199

10+
@deprecated('Use ``linefigure`` instead.')
2011
def figure1d(*args, style: Literal['line'] = 'line', **kwargs):
2112
"""
2213
Create a figure to represent one-dimensional data from one or more graph node(s).
@@ -53,8 +44,6 @@ def figure1d(*args, style: Literal['line'] = 'line', **kwargs):
5344
>>> fig = pp.figure1d(in_node, norm='log')
5445
"""
5546

56-
_warn_deprecated('figure1d', 'linefigure')
57-
5847
if style == 'line':
5948
from .lineview import LineView
6049

@@ -63,6 +52,7 @@ def figure1d(*args, style: Literal['line'] = 'line', **kwargs):
6352
raise ValueError(f'Unsupported style={style} for figure1d.')
6453

6554

55+
@deprecated('Use ``imagefigure`` instead.')
6656
def figure2d(*args, style: Literal['image'] = 'image', **kwargs):
6757
"""
6858
Create a figure to represent two-dimensional data from a graph node.
@@ -91,8 +81,6 @@ def figure2d(*args, style: Literal['image'] = 'image', **kwargs):
9181
>>> fig = pp.figure2d(in_node, norm='log')
9282
"""
9383

94-
_warn_deprecated('figure2d', 'imagefigure')
95-
9684
if style == 'image':
9785
from .imageview import ImageView
9886

@@ -101,6 +89,7 @@ def figure2d(*args, style: Literal['image'] = 'image', **kwargs):
10189
raise ValueError(f'Unsupported style={style} for figure2d.')
10290

10391

92+
@deprecated('Use ``scatter3dfigure`` instead.')
10493
def figure3d(*args, style: Literal['scatter'] = 'scatter', **kwargs):
10594
"""
10695
Create a figure to represent three-dimensional data from a graph node.
@@ -129,8 +118,6 @@ def figure3d(*args, style: Literal['scatter'] = 'scatter', **kwargs):
129118
>>> fig = pp.figure3d(in_node, norm='log')
130119
"""
131120

132-
_warn_deprecated('figure3d', 'scatter3dfigure')
133-
134121
if style == 'scatter':
135122
from .scatter3dview import Scatter3dView
136123

src/plopp/graphics/imageview.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,20 @@ def imagefigure(*args, **kwargs):
119119
Create a figure to represent two-dimensional data from one or more graph node(s).
120120
121121
.. versionadded:: 24.04.0
122+
123+
Examples
124+
--------
125+
Create an input node and attach an ``imagefigure`` as a view:
126+
127+
>>> da = pp.data.data2d()
128+
>>> in_node = pp.Node(da)
129+
>>> fig = pp.imagefigure(in_node)
130+
131+
With a customization argument to make the color scale logarithmic:
132+
133+
>>> da = pp.data.data2d()
134+
>>> in_node = pp.Node(da)
135+
>>> fig = pp.imagefigure(in_node, norm='log')
122136
"""
123137

124138
return backends.figure2d(ImageView, *args, **kwargs)

src/plopp/graphics/lineview.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,28 @@ def linefigure(*args, **kwargs):
122122
Create a figure to represent one-dimensional data from one or more graph node(s).
123123
124124
.. versionadded:: 24.04.0
125+
126+
Examples
127+
--------
128+
Create an input node and attach a ``linefigure`` as a view:
129+
130+
>>> da = pp.data.data1d()
131+
>>> in_node = pp.Node(da)
132+
>>> fig = pp.linefigure(in_node)
133+
134+
Visualize two data arrays on the same figure:
135+
136+
>>> a = pp.data.data1d()
137+
>>> b = 3 * a
138+
>>> a_node = pp.Node(a)
139+
>>> b_node = pp.Node(b)
140+
>>> fig = pp.linefigure(a_node, b_node)
141+
142+
With a customization argument to make the vertical scale logarithmic:
143+
144+
>>> da = pp.data.data1d()
145+
>>> in_node = pp.Node(da)
146+
>>> fig = pp.linefigure(in_node, norm='log')
125147
"""
126148

127149
return backends.figure2d(LineView, *args, **kwargs)

src/plopp/graphics/scatter3dview.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,20 @@ def scatter3dfigure(*args, **kwargs):
192192
Create a figure to represent three-dimensional data from one or more graph node(s).
193193
194194
.. versionadded:: 24.04.0
195+
196+
Examples
197+
--------
198+
Create an input node and attach a ``scatter3dfigure`` as a view:
199+
200+
>>> da = pp.data.scatter()
201+
>>> in_node = pp.Node(da)
202+
>>> fig = pp.scatter3dfigure(in_node)
203+
204+
With a customization argument to make the color scale logarithmic:
205+
206+
>>> da = pp.data.scatter()
207+
>>> in_node = pp.Node(da)
208+
>>> fig = pp.scatter3dfigure(in_node, norm='log')
195209
"""
196210

197211
return backends.figure3d(Scatter3dView, *args, **kwargs)

src/plopp/graphics/scatterview.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ def scatterfigure(*args, **kwargs):
9494
Create a figure to represent scatter data from one or more graph node(s).
9595
9696
.. versionadded:: 24.04.0
97+
98+
Examples
99+
--------
100+
Create an input node and attach a ``scatterfigure`` as a view:
101+
102+
>>> da = pp.data.scatter()
103+
>>> in_node = pp.Node(da)
104+
>>> fig = pp.scatterfigure(in_node)
105+
106+
A scatter figure with a color bar (using the data values for the color scale):
107+
108+
>>> da = pp.data.scatter()
109+
>>> in_node = pp.Node(da)
110+
>>> fig = pp.scatterfigure(in_node, cbar=True)
97111
"""
98112

99113
return backends.figure2d(ScatterView, *args, **kwargs)

src/plopp/utils.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
# Copyright (c) 2024 Scipp contributors (https://github.com/scipp)
3+
4+
import functools
5+
import warnings
6+
from typing import Callable
7+
8+
from .core.typing import VisibleDeprecationWarning
9+
10+
11+
def deprecated(message: str = '') -> Callable:
12+
def decorator(function: Callable) -> Callable:
13+
@functools.wraps(function)
14+
def wrapper(*args, **kwargs):
15+
warnings.warn(
16+
f'{function.__name__} is deprecated. {message}',
17+
VisibleDeprecationWarning,
18+
stacklevel=2,
19+
)
20+
return function(*args, **kwargs)
21+
22+
return wrapper
23+
24+
return decorator
25+
26+
27+
__all__ = ['deprecated']

src/plopp/widgets/cut3d.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
import scipp as sc
1111

1212
from ..core import View, node
13+
from ..utils import deprecated
1314
from .debounce import debounce
1415
from .style import BUTTON_LAYOUT
1516
from .tools import PlusMinusTool
1617

1718

19+
@deprecated("Use ``Clip3dTool`` instead.")
1820
class Cut3dTool(ipw.HBox):
1921
"""
2022
A tool that provides a slider to extract a plane of points in a three-dimensional
@@ -220,11 +222,14 @@ def decrease_thickness(self):
220222
self._add_cut()
221223

222224

225+
@deprecated("Use ``ClippingPlanes`` instead.")
223226
class TriCutTool(ipw.HBox):
224227
"""
225228
A collection of :class:`Cut3dTool` to make spatial cuts in the X, Y, and Z
226229
directions on a three-dimensional scatter plot.
227230
231+
.. deprecated:: v24.04.0
232+
228233
Parameters
229234
----------
230235
fig:

0 commit comments

Comments
 (0)