mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 03:31:50 +02:00
fix(curve): color_map_z setting works
This commit is contained in:
@ -753,7 +753,7 @@ class BECCurve(RPCBase):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
@rpc_call
|
@rpc_call
|
||||||
def set_colormap(self, colormap: "str"):
|
def set_colormap_z(self, colormap: "str"):
|
||||||
"""
|
"""
|
||||||
Set the colormap for the scatter plot z gradient.
|
Set the colormap for the scatter plot z gradient.
|
||||||
|
|
||||||
|
@ -86,9 +86,10 @@ class JupyterConsoleWindow(QWidget): # pragma: no cover:
|
|||||||
self.console_layout.addWidget(self.console)
|
self.console_layout.addWidget(self.console)
|
||||||
|
|
||||||
def _init_figure(self):
|
def _init_figure(self):
|
||||||
self.figure.plot(x_name="samx", y_name="bpm4d")
|
self.figure.plot(x_name="samx", y_name="samy", z_name="bpm4i", color_map_z="cividis")
|
||||||
self.figure.motor_map("samx", "samy")
|
self.figure.motor_map("samx", "samy")
|
||||||
self.figure.image("eiger", color_map="viridis", vrange=(0, 100))
|
self.figure.image("eiger", color_map="viridis", vrange=(0, 100))
|
||||||
|
self.figure.add_plot(x_name="samx", y_name="samy", z_name="bpm4i", color_map_z="magma")
|
||||||
|
|
||||||
self.figure.change_layout(2, 2)
|
self.figure.change_layout(2, 2)
|
||||||
|
|
||||||
@ -97,8 +98,6 @@ class JupyterConsoleWindow(QWidget): # pragma: no cover:
|
|||||||
self.w3 = self.figure[1, 0]
|
self.w3 = self.figure[1, 0]
|
||||||
|
|
||||||
# curves for w1
|
# curves for w1
|
||||||
self.w1.plot(x_name="samx", y_name="samy", z_name="bpm4i")
|
|
||||||
self.w1.plot(x_name="samx", y_name="samy", z_name="bpm3a")
|
|
||||||
self.c1 = self.w1.get_config()
|
self.c1 = self.w1.get_config()
|
||||||
|
|
||||||
def _init_dock(self):
|
def _init_dock(self):
|
||||||
|
@ -364,7 +364,7 @@ class BECWaveform(BECPlotBase):
|
|||||||
parent_id=self.gui_id,
|
parent_id=self.gui_id,
|
||||||
label=label,
|
label=label,
|
||||||
color=color,
|
color=color,
|
||||||
color_map=color_map_z,
|
color_map_z=color_map_z,
|
||||||
source=curve_source,
|
source=curve_source,
|
||||||
signals=Signal(
|
signals=Signal(
|
||||||
source=curve_source,
|
source=curve_source,
|
||||||
@ -564,7 +564,7 @@ class BECWaveform(BECPlotBase):
|
|||||||
if curve.config.signals.z:
|
if curve.config.signals.z:
|
||||||
data_z = data[z_name][z_entry].val
|
data_z = data[z_name][z_entry].val
|
||||||
color_z = self._make_z_gradient(
|
color_z = self._make_z_gradient(
|
||||||
data_z, curve.config.colormap
|
data_z, curve.config.color_map_z
|
||||||
) # TODO decide how to implement custom gradient
|
) # TODO decide how to implement custom gradient
|
||||||
except TypeError:
|
except TypeError:
|
||||||
continue
|
continue
|
||||||
|
@ -3,7 +3,8 @@ from __future__ import annotations
|
|||||||
from typing import Any, Literal, Optional
|
from typing import Any, Literal, Optional
|
||||||
|
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field, field_validator
|
||||||
|
from pydantic_core import PydanticCustomError
|
||||||
from qtpy import QtCore
|
from qtpy import QtCore
|
||||||
|
|
||||||
from bec_widgets.utils import BECConnector, ConnectionConfig
|
from bec_widgets.utils import BECConnector, ConnectionConfig
|
||||||
@ -43,7 +44,22 @@ class CurveConfig(ConnectionConfig):
|
|||||||
)
|
)
|
||||||
source: Optional[str] = Field(None, description="The source of the curve.")
|
source: Optional[str] = Field(None, description="The source of the curve.")
|
||||||
signals: Optional[Signal] = Field(None, description="The signal of the curve.")
|
signals: Optional[Signal] = Field(None, description="The signal of the curve.")
|
||||||
colormap: Optional[str] = Field("plasma", description="The colormap of the curves z gradient.")
|
color_map_z: Optional[str] = Field(
|
||||||
|
"plasma", description="The colormap of the curves z gradient.", validate_default=True
|
||||||
|
)
|
||||||
|
model_config: dict = {"validate_assignment": True}
|
||||||
|
|
||||||
|
@field_validator("color_map_z")
|
||||||
|
def validate_color_map(cls, v, values):
|
||||||
|
if v is not None and v != "":
|
||||||
|
available_colormaps = pg.colormap.listMaps()
|
||||||
|
if v not in available_colormaps:
|
||||||
|
raise PydanticCustomError(
|
||||||
|
"unsupported colormap",
|
||||||
|
f"Colormap '{v}' not found in the current installation of pyqtgraph. Choose on the following: {available_colormaps}.",
|
||||||
|
{"wrong_value": v},
|
||||||
|
)
|
||||||
|
return v
|
||||||
|
|
||||||
|
|
||||||
class BECCurve(BECConnector, pg.PlotDataItem):
|
class BECCurve(BECConnector, pg.PlotDataItem):
|
||||||
@ -54,7 +70,7 @@ class BECCurve(BECConnector, pg.PlotDataItem):
|
|||||||
"set",
|
"set",
|
||||||
"set_data",
|
"set_data",
|
||||||
"set_color",
|
"set_color",
|
||||||
"set_colormap",
|
"set_colormap_z",
|
||||||
"set_symbol",
|
"set_symbol",
|
||||||
"set_symbol_color",
|
"set_symbol_color",
|
||||||
"set_symbol_size",
|
"set_symbol_size",
|
||||||
@ -130,7 +146,7 @@ class BECCurve(BECConnector, pg.PlotDataItem):
|
|||||||
# Mapping of keywords to setter methods
|
# Mapping of keywords to setter methods
|
||||||
method_map = {
|
method_map = {
|
||||||
"color": self.set_color,
|
"color": self.set_color,
|
||||||
"colormap": self.set_colormap,
|
"color_map_z": self.set_color_map_z,
|
||||||
"symbol": self.set_symbol,
|
"symbol": self.set_symbol,
|
||||||
"symbol_color": self.set_symbol_color,
|
"symbol_color": self.set_symbol_color,
|
||||||
"symbol_size": self.set_symbol_size,
|
"symbol_size": self.set_symbol_size,
|
||||||
@ -205,14 +221,15 @@ class BECCurve(BECConnector, pg.PlotDataItem):
|
|||||||
self.config.pen_style = pen_style
|
self.config.pen_style = pen_style
|
||||||
self.apply_config()
|
self.apply_config()
|
||||||
|
|
||||||
def set_colormap(self, colormap: str):
|
def set_color_map_z(self, colormap: str):
|
||||||
"""
|
"""
|
||||||
Set the colormap for the scatter plot z gradient.
|
Set the colormap for the scatter plot z gradient.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
colormap(str): Colormap for the scatter plot.
|
colormap(str): Colormap for the scatter plot.
|
||||||
"""
|
"""
|
||||||
self.config.colormap = colormap
|
self.config.color_map_z = colormap
|
||||||
|
self.apply_config()
|
||||||
|
|
||||||
def get_data(self) -> tuple[np.ndarray, np.ndarray]:
|
def get_data(self) -> tuple[np.ndarray, np.ndarray]:
|
||||||
"""
|
"""
|
||||||
|
@ -73,7 +73,7 @@ def test_create_waveform1D_by_config(bec_figure):
|
|||||||
"parent_id": "widget_1",
|
"parent_id": "widget_1",
|
||||||
"label": "bpm4i-bpm4i",
|
"label": "bpm4i-bpm4i",
|
||||||
"color": "#cc4778",
|
"color": "#cc4778",
|
||||||
"colormap": "plasma",
|
"color_map_z": "plasma",
|
||||||
"symbol": "o",
|
"symbol": "o",
|
||||||
"symbol_color": None,
|
"symbol_color": None,
|
||||||
"symbol_size": 5,
|
"symbol_size": 5,
|
||||||
@ -105,7 +105,7 @@ def test_create_waveform1D_by_config(bec_figure):
|
|||||||
"parent_id": "widget_1",
|
"parent_id": "widget_1",
|
||||||
"label": "curve-custom",
|
"label": "curve-custom",
|
||||||
"color": "blue",
|
"color": "blue",
|
||||||
"colormap": "plasma",
|
"color_map_z": "plasma",
|
||||||
"symbol": "o",
|
"symbol": "o",
|
||||||
"symbol_color": None,
|
"symbol_color": None,
|
||||||
"symbol_size": 5,
|
"symbol_size": 5,
|
||||||
@ -360,7 +360,7 @@ def test_curve_add_by_config(bec_figure):
|
|||||||
"parent_id": "widget_1",
|
"parent_id": "widget_1",
|
||||||
"label": "bpm4i-bpm4i",
|
"label": "bpm4i-bpm4i",
|
||||||
"color": "#cc4778",
|
"color": "#cc4778",
|
||||||
"colormap": "plasma",
|
"color_map_z": "plasma",
|
||||||
"symbol": "o",
|
"symbol": "o",
|
||||||
"symbol_color": None,
|
"symbol_color": None,
|
||||||
"symbol_size": 5,
|
"symbol_size": 5,
|
||||||
|
Reference in New Issue
Block a user