diff --git a/sohstationviewer/view/plotting/plotting_widget/plotting.py b/sohstationviewer/view/plotting/plotting_widget/plotting.py index bbeb09f686a81289d5ae9c1003b30bc5b387db78..14b25033460dbc786210231e02ab446992ed2d6a 100644 --- a/sohstationviewer/view/plotting/plotting_widget/plotting.py +++ b/sohstationviewer/view/plotting/plotting_widget/plotting.py @@ -77,8 +77,10 @@ class Plotting: if chan_db_info['valueColors'] in [None, 'None', '']: chan_db_info['valueColors'] = '*:W' value_colors = chan_db_info['valueColors'].split('|') + colors = [] for vc in value_colors: v, c = vc.split(':') + colors.append(c) val = get_val(v) if c == '_': prev_val = val @@ -106,9 +108,14 @@ class Plotting: total_samples = len(x) x = sorted(x) + if len(colors) != 1: + sample_no_colors = [clr['W']] + else: + sample_no_colors = [clr[colors[0]]] + self.plotting_axes.set_axes_info( - ax, [total_samples], chan_db_info=chan_db_info, - linked_ax=linked_ax) + ax, [total_samples], sample_no_colors=sample_no_colors, + chan_db_info=chan_db_info, linked_ax=linked_ax) if linked_ax is None: ax.x = x else: @@ -170,6 +177,7 @@ class Plotting: ax.set_ylim(-2, 2) self.plotting_axes.set_axes_info( ax, [len(points_list[0]), len(points_list[1])], + sample_no_colors=colors, chan_db_info=chan_db_info, linked_ax=linked_ax) if linked_ax is None: ax.x = x @@ -205,7 +213,8 @@ class Plotting: x_list = c_data['times'] total_x = sum([len(x) for x in x_list]) self.plotting_axes.set_axes_info( - ax, [total_x], chan_db_info=chan_db_info, linked_ax=linked_ax) + ax, [total_x], sample_no_colors=[clr[color]], + chan_db_info=chan_db_info, linked_ax=linked_ax) for x in x_list: ax.plot(x, [0] * len(x), marker='s', markersize=1.5, @@ -252,15 +261,7 @@ class Plotting: self.parent.plotting_bot, plot_h) x_list, y_list = c_data['times'], c_data['data'] - if chan_id == 'GPS Lk/Unlk': - sample_no_list = [] - sample_no_list.append(np.where(y_list[0] == -1)[0].size) - sample_no_list.append(np.where(y_list[0] == 1)[0].size) - else: - sample_no_list = [sum([len(x) for x in x_list])] - self.plotting_axes.set_axes_info( - ax, sample_no_list, chan_db_info=chan_db_info, - info=info, y_list=y_list, linked_ax=linked_ax) + colors = {} if chan_db_info['valueColors'] not in [None, 'None', '']: color_parts = chan_db_info['valueColors'].split('|') @@ -274,6 +275,20 @@ class Plotting: if 'D' in colors: d_color = colors['D'] has_dot = True + + if chan_id == 'GPS Lk/Unlk': + sample_no_list = [] + sample_no_list.append(np.where(y_list[0] == -1)[0].size) + sample_no_list.append(np.where(y_list[0] == 1)[0].size) + sample_no_colors = [clr[d_color], clr[d_color]] + else: + sample_no_list = [sum([len(x) for x in x_list])] + sample_no_colors = [clr[d_color]] + self.plotting_axes.set_axes_info( + ax, sample_no_list, sample_no_colors=sample_no_colors, + chan_db_info=chan_db_info, + info=info, y_list=y_list, linked_ax=linked_ax) + for x, y in zip(x_list, y_list): if not has_dot: # set marker to be able to click point for info diff --git a/sohstationviewer/view/plotting/plotting_widget/plotting_axes.py b/sohstationviewer/view/plotting/plotting_widget/plotting_axes.py index 06a3c0ab22b48e3f666ee9325b1572037c440586..ce0385e32337c4d9b074ec5851043cff1f695c57 100644 --- a/sohstationviewer/view/plotting/plotting_widget/plotting_axes.py +++ b/sohstationviewer/view/plotting/plotting_widget/plotting_axes.py @@ -1,5 +1,7 @@ -from typing import List +from typing import List, Optional, Dict +import numpy as np +from matplotlib.axes import Axes from matplotlib.patches import ConnectionPatch, Rectangle from matplotlib.ticker import AutoMinorLocator from matplotlib import pyplot as pl @@ -10,6 +12,7 @@ from sohstationviewer.controller.plotting_data import ( get_gaps, get_time_ticks, get_unit_bitweight) from sohstationviewer.conf import constants +from sohstationviewer.view.util.color import clr class PlottingAxes: @@ -148,24 +151,27 @@ class PlottingAxes: ax.patch.set_alpha(0) return ax - def set_axes_info(self, ax, sample_no_list, - label=None, info='', y_list=None, chan_db_info=None, - linked_ax=None): + def set_axes_info(self, ax: Axes, + sample_no_list: List[int], + sample_no_colors: List[str] = [clr['W'], clr['W']], + label: Optional[str] = None, + info: str = '', + y_list: Optional[np.ndarray] = None, + chan_db_info: Optional[Dict] = None, + linked_ax: Optional[Axes] = None): """ Draw plot's title, sub title, sample total label, center line, y labels for a channel. - :param ax: matplotlib.axes.Axes - axes of a channel - :param sample_no_list: [int,] - list of totals of different sample - groups - :param label: str/None - title of the plot. - If None, show chan_db_info['label'] - :param info: str - additional info to show in sub title which is + :param ax: axes of a channel + :param sample_no_list: list of totals of different sample groups + :param sample_no_colors: list of color to display sample numbers + :param label: title of the plot. If None, show chan_db_info['label'] + :param info: additional info to show in sub title which is smaller and under title on the left side - :param y: numpy.array - y values of the channel, to show min/max labels - and min/max lines - :param chan_db_info: dict - info of channel from database - :param linked_ax: matplotlib.axes.Axes/None - + :param y: y values of the channel for min/max labels, min/max lines + :param chan_db_info: info of channel from database + :param linked_ax: if linked_ax is None, this is a main channel, label of channel will be displayed with title's format, on top right of plot. if linked_ax is not None, this is a channel using main channel's @@ -181,6 +187,7 @@ class PlottingAxes: if label is None: label = chan_db_info['label'] + title_ver_alignment = 'center' # set info in subtitle under title if linked_ax is not None: @@ -223,7 +230,7 @@ class PlottingAxes: verticalalignment='center', rotation='horizontal', transform=ax.transAxes, - color=self.parent.display_color['basic'], + color=sample_no_colors[0], size=self.parent.font_size ) else: @@ -233,7 +240,6 @@ class PlottingAxes: # on data created in trim_downsample_chan_with_spr_less_or_equal_1 # and won't be changed in set_lim, then don't need to assign a # variable for it. - # bottom ax.text( 1.005, 0.05, @@ -242,7 +248,7 @@ class PlottingAxes: verticalalignment='center', rotation='horizontal', transform=ax.transAxes, - color=self.parent.display_color['basic'], + color=sample_no_colors[0], size=self.parent.font_size ) # top @@ -253,15 +259,12 @@ class PlottingAxes: verticalalignment='center', rotation='horizontal', transform=ax.transAxes, - color=self.parent.display_color['basic'], + color=sample_no_colors[1], size=self.parent.font_size ) - if linked_ax is not None: ax.set_yticks([]) - return - if y_list is None: # draw center line ax.plot([self.parent.min_x, self.parent.max_x],