Skip to content

Commit cd8c8d3

Browse files
committed
New curve statistics tools and YRangeSelection support
Fix #45
1 parent 5624c9d commit cd8c8d3

File tree

24 files changed

+505
-119
lines changed

24 files changed

+505
-119
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Changelog #
22

3-
## Version 2.7.5 ##
3+
## Version 2.8.0 ##
4+
5+
💥 New features / Enhancements:
6+
7+
* [Issue #45](https://github.com/PlotPyStack/PlotPy/issues/45) - Add support for new curve statistics tools: `XCurveStatsTool` and `YCurveStatsTool`
8+
* These tools are similar to the existing `CurveStatsTool`, but they compute statistics for the X and Y coordinates of the curve points, respectively
9+
* They can be added to the plot widget using `plot_widget.manager.add_tool(XCurveStatsTool)` or `plot_widget.manager.add_tool(YCurveStatsTool)`
10+
* The tools display a table with the computed statistics (mean, median, standard deviation, etc.) for the X or Y coordinates of the curve points
411

512
🛠️ Bug fixes:
613

doc/features/items/overview.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ The following shape items are available:
5959
* :py:class:`.EllipseShape`
6060
* :py:class:`.Axes`
6161
* :py:class:`.XRangeSelection`
62+
* :py:class:`.YRangeSelection`
6263
* :py:class:`.Marker`
6364
* :py:class:`.RectangleSVGShape`
6465
* :py:class:`.SquareSVGShape`

doc/features/items/reference.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ Shapes
9898
:members:
9999
.. autoclass:: plotpy.items.XRangeSelection
100100
:members:
101+
.. autoclass:: plotpy.items.YRangeSelection
102+
:members:
101103
.. autoclass:: plotpy.items.Marker
102104
:members:
103105
.. autoclass:: plotpy.items.RectangleSVGShape

doc/features/tools/reference.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ Shape tools
9292
Curve tools
9393
^^^^^^^^^^^
9494

95-
.. autoclass:: plotpy.tools.CurveStatsTool
95+
.. autoclass:: plotpy.tools.XCurveStatsTool
96+
:members:
97+
.. autoclass:: plotpy.tools.YCurveStatsTool
9698
:members:
9799
.. autoclass:: plotpy.tools.SelectPointTool
98100
:members:

plotpy/builder/curvemarker.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
HistogramItem,
3333
Marker,
3434
XRangeSelection,
35+
YRangeSelection,
3536
)
3637
from plotpy.plot import BasePlot
3738
from plotpy.styles import (
@@ -58,6 +59,7 @@ class CurveMarkerCursorBuilder:
5859

5960
def __init__(self):
6061
self.style = style_generator()
62+
self.range = self.xrange # Compatibility with old code
6163

6264
# ---- Plot items -----------------------------------------------------------------
6365

@@ -670,8 +672,8 @@ def phistogram(
670672
self.__set_curve_axes(hist, xaxis, yaxis)
671673
return hist
672674

673-
def range(self, xmin: float, xmax: float) -> XRangeSelection:
674-
"""Make a range `plot item`
675+
def xrange(self, xmin: float, xmax: float) -> XRangeSelection:
676+
"""Make a X-range `plot item`
675677
676678
Args:
677679
xmin: minimum value
@@ -682,6 +684,18 @@ def range(self, xmin: float, xmax: float) -> XRangeSelection:
682684
"""
683685
return XRangeSelection(xmin, xmax)
684686

687+
def yrange(self, ymin: float, ymax: float) -> YRangeSelection:
688+
"""Make a Y-range `plot item`
689+
690+
Args:
691+
ymin: minimum value
692+
ymax: maximum value
693+
694+
Returns:
695+
:py:class:`.YRangeSelection` object
696+
"""
697+
return YRangeSelection(ymin, ymax)
698+
685699
def vcursor(
686700
self,
687701
x: float,

plotpy/builder/label.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
RectangleShape,
3636
SelectedLegendBoxItem,
3737
XRangeSelection,
38+
YRangeSelection,
3839
)
3940
from plotpy.styles import LabelParam, LabelParamWithContents, LegendParam
4041

@@ -166,13 +167,14 @@ def info_label(
166167

167168
def range_info_label(
168169
self,
169-
range: XRangeSelection,
170+
range: XRangeSelection | YRangeSelection,
170171
anchor: str,
171172
label: str,
172173
function: Callable = None,
173174
title: str | None = None,
174175
) -> DataInfoLabel:
175-
"""Make an info label `plot item` showing an XRangeSelection object infos
176+
"""Make an info label `plot item` showing an `XRangeSelection` or
177+
`YRangeSelection` object information.
176178
177179
Args:
178180
range: range selection object
@@ -189,7 +191,7 @@ def range_info_label(
189191
190192
x = linspace(-10, 10, 10)
191193
y = sin(sin(sin(x)))
192-
range = make.range(-2, 2)
194+
range = make.xrange(-2, 2)
193195
disp = make.range_info_label(range, 'BL', "x = %.1f ± %.1f cm",
194196
lambda x, dx: (x, dx))
195197
"""
@@ -198,7 +200,7 @@ def range_info_label(
198200

199201
def computation(
200202
self,
201-
range: XRangeSelection,
203+
range: XRangeSelection | YRangeSelection,
202204
anchor: str,
203205
label: str,
204206
curve: CurveItem,
@@ -223,7 +225,11 @@ def computation(
223225
return self.computations(range, anchor, [(curve, label, function)], title=title)
224226

225227
def computations(
226-
self, range: XRangeSelection, anchor: str, specs: list, title: str | None = None
228+
self,
229+
range: XRangeSelection | YRangeSelection,
230+
anchor: str,
231+
specs: list,
232+
title: str | None = None,
227233
) -> DataInfoLabel:
228234
"""Make computation labels `plot item`
229235

plotpy/config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -595,10 +595,10 @@ def get_plotpy_defaults() -> dict[str, int | float | str | bool]:
595595
"range/line/color": "#ff9393",
596596
"range/line/width": 1,
597597
"range/sel_line/style": "SolidLine",
598-
"range/sel_line/color": "#ff0000",
598+
"range/sel_line/color": "#ff3333",
599599
"range/sel_line/width": 2,
600-
"range/fill": "#ff0000",
601-
"range/shade": 0.15,
600+
"range/fill": "#ff3333",
601+
"range/shade": 0.1,
602602
"range/symbol/marker": "Ellipse",
603603
"range/symbol/size": 7,
604604
"range/symbol/edgecolor": MAIN_BG_COLOR,
@@ -607,7 +607,7 @@ def get_plotpy_defaults() -> dict[str, int | float | str | bool]:
607607
"range/sel_symbol/marker": "Ellipse",
608608
"range/sel_symbol/size": 9,
609609
"range/sel_symbol/edgecolor": MAIN_BG_COLOR,
610-
"range/sel_symbol/facecolor": "#ff0000",
610+
"range/sel_symbol/facecolor": "#ff3333",
611611
"range/sel_symbol/alpha": 0.9,
612612
"range/multi/color": "#806060",
613613
# Default parameters for plot axes

plotpy/data/icons/yrange.png

486 Bytes
Loading

plotpy/io.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ def register_serializable_items(modname, classnames):
606606
"MaskedXYImageItem",
607607
"Marker",
608608
"XRangeSelection",
609+
"YRangeSelection",
609610
"PolygonShape",
610611
"PointShape",
611612
"SegmentShape",

plotpy/items/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,5 @@
6565
SegmentShape,
6666
SquareSVGShape,
6767
XRangeSelection,
68+
YRangeSelection,
6869
)

0 commit comments

Comments
 (0)