Skip to content

Commit

Permalink
ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
jackbdoughty committed Nov 7, 2024
1 parent 603d530 commit 0904ca0
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions src/ibex_bluesky_core/callbacks/plotting.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""IBEX plotting callbacks."""

import logging
from typing import Any

import matplotlib
import matplotlib.pyplot as plt
Expand All @@ -15,7 +16,24 @@
class LivePlot(_DefaultLivePlot):
"""Live plot, customized for IBEX."""

def __init__(self, y, x=None, yerr=None, *args, **kwargs):
def __init__(
self,
y: str,
x: str | None = None,
yerr: str | None = None,
*args: Any, # noqa: ANN401
**kwargs: Any, # noqa: ANN401
) -> None:
"""Initialise LivePlot.
Args:
y (str): The name of the dependant variable.
x (str or None, optional): The name of the independant variable.
yerr (str or None, optional): Name of uncertainties signal.
*args: As per mpl_plotting.py
**kwargs: As per mpl_plotting.py
"""
super().__init__(y=y, x=x, *args, **kwargs)

Check failure on line 37 in src/ibex_bluesky_core/callbacks/plotting.py

View workflow job for this annotation

GitHub Actions / call-linter-workflow / ruff

Ruff (B026)

src/ibex_bluesky_core/callbacks/plotting.py:37:36: B026 Star-arg unpacking after a keyword argument is strongly discouraged
if yerr is not None:
self.yerr, *others = get_obj_fields([yerr])
Expand All @@ -24,26 +42,28 @@ def __init__(self, y, x=None, yerr=None, *args, **kwargs):
self.yerr_data = []

def _show_plot(self) -> None:
"""Call plt.show()."""
# Play nicely with the "normal" backends too - only force show if we're
# actually using our custom backend.
if "genie_python" in matplotlib.get_backend():
plt.show()

def event(self, doc: Event):
def event(self, doc: Event) -> None:
"""Process an event document (delegate to superclass, then show the plot)."""
new_yerr = None if self.yerr is None else doc["data"][self.yerr]
self.update_yerr(new_yerr)
super().event(doc)
self._show_plot()

def update_plot(self):
def update_plot(self) -> None:
"""Create error bars if needed, then update plot."""
if self.yerr is not None:
self.ax.errorbar(x=self.x_data, y=self.y_data, yerr=self.yerr_data, fmt="none")
self.ax.errorbar(x=self.x_data, y=self.y_data, yerr=self.yerr_data, fmt="none") # type: ignore
super().update_plot()

def update_yerr(self, y_err):
# super.update_caches(x, y)
self.yerr_data.append(y_err)
def update_yerr(self, yerr: float | None) -> None:
"""Update uncertainties data."""
self.yerr_data.append(yerr)

def start(self, doc: RunStart) -> None:
"""Process an start document (delegate to superclass, then show the plot)."""
Expand Down

0 comments on commit 0904ca0

Please sign in to comment.