-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy patherrorbar.py
More file actions
63 lines (51 loc) · 1.91 KB
/
errorbar.py
File metadata and controls
63 lines (51 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# -*- coding: utf-8 -*-
from __future__ import annotations
from typing import TYPE_CHECKING
from guidata.dataset import BoolItem, ChoiceItem, ColorItem, DataSet, FloatItem, IntItem
from qtpy import QtGui as QG
from plotpy.config import _
if TYPE_CHECKING:
from plotpy.items import ErrorBarCurveItem
class ErrorBarParam(DataSet):
"""Error bar style parameters for a curve."""
mode = ChoiceItem(
_("Display"),
default=0,
choices=[_("error bars with caps (x, y)"), _("error area (y)")],
help=_(
"Note: only y-axis error bars are shown in "
"error area mode\n(width and cap parameters "
"will also be ignored)"
),
)
color = ColorItem(_("Color"), default="darkred")
alpha = FloatItem(
_("Alpha"), default=0.9, min=0, max=1, help=_("Error bar transparency")
)
width = FloatItem(_("Width"), default=1.0, min=1)
cap = IntItem(_("Cap"), default=4, min=0)
ontop = BoolItem(_("set to foreground"), _("Visibility"), default=False)
def update_param(self, item: ErrorBarCurveItem) -> None:
"""
Update the parameters associated with the error bar item.
Args:
item: The error bar item from which to update the parameters.
"""
color = item.errorPen.color()
self.color = str(color.name())
self.alpha = color.alphaF()
self.width = item.errorPen.widthF()
self.cap = item.errorCap
self.ontop = item.errorOnTop
def update_item(self, item: ErrorBarCurveItem) -> None:
"""
Update the error bar item with the parameters.
Args:
item: The error bar item to update.
"""
color = QG.QColor(self.color)
color.setAlphaF(self.alpha)
item.errorPen = QG.QPen(color, self.width)
item.errorBrush = QG.QBrush(color)
item.errorCap = self.cap
item.errorOnTop = self.ontop