From 0f8160f8c0a4e46e3e05059e2fa33c73ce4babf7 Mon Sep 17 00:00:00 2001 From: ldam <ldam@passcal.nmt.edu> Date: Mon, 18 Sep 2023 19:43:14 -0600 Subject: [PATCH] simplify drawing sample numbers' labels to give plotting function have more control on this --- .../plotting/plotting_widget/plotting_axes.py | 79 ++++++++----------- 1 file changed, 34 insertions(+), 45 deletions(-) diff --git a/sohstationviewer/view/plotting/plotting_widget/plotting_axes.py b/sohstationviewer/view/plotting/plotting_widget/plotting_axes.py index 7cc06ddde..caeff9197 100644 --- a/sohstationviewer/view/plotting/plotting_widget/plotting_axes.py +++ b/sohstationviewer/view/plotting/plotting_widget/plotting_axes.py @@ -12,7 +12,6 @@ from sohstationviewer.controller.plotting_data import ( get_time_ticks, get_unit_bitweight, get_disk_size_format) from sohstationviewer.conf import constants -from sohstationviewer.view.util.color import clr class PlottingAxes: @@ -154,10 +153,32 @@ class PlottingAxes: ax.patch.set_alpha(0) return ax + def create_sample_no_label(self, ax: Axes, pos_y: float, + sample_no: int, color: str) -> None: + """ + Create label to display sample number + :param ax: the axes of the label + :param pos_y: vertical position for the label + :param sample_no: total of samples + :param color: color of the text in the label + """ + if sample_no is None: + return + return ax.text( + 1.005, pos_y, + sample_no, + horizontalalignment='left', + verticalalignment='center', + rotation='horizontal', + transform=ax.transAxes, + color=color, + size=self.parent.font_size + ) + def set_axes_info(self, ax: Axes, sample_no_list: List[int], - sample_no_colors: List[str] = [clr['W'], clr['W']], - sample_no_pos: List[float] = [0.05, 0.95], + sample_no_colors: List[str], + sample_no_pos: List[float], label: Optional[str] = None, info: str = '', y_list: Optional[np.ndarray] = None, @@ -221,48 +242,16 @@ class PlottingAxes: ) # set samples' total on right side - if len(sample_no_list) == 1: - # center_total_point_lbl: The label to display total number of data - # points for plots whose ax has attribute x_list. - # The plotTypes that use this label are linesDot, linesSRate, - # linesMassPos, dotForTime, multiColorDot - ax.center_total_point_lbl = ax.text( - 1.005, 0.5, - sample_no_list[0], - horizontalalignment='left', - verticalalignment='center', - rotation='horizontal', - transform=ax.transAxes, - color=sample_no_colors[0], - size=self.parent.font_size - ) - else: - # bottom_total_point_lbl, top_total_point_lbl are label to diplay - # total number of data points which are splitted into top - # and bottom. The ax needs to include attributes x_bottom and x_top - # The plotTypes that use these labels are upDownDots and linesDot - # with channel='GPS Lk/Unlk' - ax.bottom_total_point_lbl = ax.text( - 1.005, sample_no_pos[0], - sample_no_list[0], - horizontalalignment='left', - verticalalignment='center', - rotation='horizontal', - transform=ax.transAxes, - color=sample_no_colors[0], - size=self.parent.font_size - ) - # top - ax.top_total_point_lbl = ax.text( - 1.005, sample_no_pos[1], - sample_no_list[1], - horizontalalignment='left', - verticalalignment='center', - rotation='horizontal', - transform=ax.transAxes, - color=sample_no_colors[1], - size=self.parent.font_size - ) + # bottom + ax.bottom_total_point_lbl = self.create_sample_no_label( + ax, sample_no_pos[0], sample_no_list[0], sample_no_colors[0]) + # center + ax.center_total_point_lbl = self.create_sample_no_label( + ax, sample_no_pos[1], sample_no_list[1], sample_no_colors[1]) + # top + ax.top_total_point_lbl = self.create_sample_no_label( + ax, sample_no_pos[2], sample_no_list[2], sample_no_colors[2]) + if linked_ax is not None: ax.set_yticks([]) return -- GitLab