diff --git a/skill_metrics/get_default_markers.py b/skill_metrics/get_default_markers.py index bca622e..7056ba2 100755 --- a/skill_metrics/get_default_markers.py +++ b/skill_metrics/get_default_markers.py @@ -1,5 +1,13 @@ +import warnings +from itertools import cycle, islice, product + import matplotlib.colors as clr +# Define list of marker symbols and colors +MARKERS = ["+", "o", "x", "s", "d", "^", "v", "p", "h", "*"] +COLORS = ["r", "b", "g", "c", "m", "y", "k"] + + def get_default_markers(X, option: dict) -> tuple[list, list]: ''' Provides a list of default markers and marker colors. @@ -24,38 +32,25 @@ def get_default_markers(X, option: dict) -> tuple[list, list]: Created on Mar 12, 2023 Revised on Mar 12, 2023 ''' - # Set face color transparency - alpha = option['alpha'] - - # Define list of marker symbols and colros - kind = ['+','o','x','s','d','^','v','p','h','*'] - colorm = ['r','b','g','c','m','y','k','gray'] - if len(X) > 80: - _disp('You must introduce new markers to plot more than 70 cases.') - _disp('The ''marker'' character array need to be extended inside the code.') - - if len(X) <= len(kind): - # Define markers with specified color - marker = [] - markercolor = [] - if option['markercolor'] is None: - for i, color in enumerate(colorm): - rgba = clr.to_rgb(color) + (alpha,) - marker.append(kind[i] + color) - markercolor.append(rgba) - else: - rgba = clr.to_rgb(option['markercolor']) + (alpha,) - for symbol in kind: - marker.append(symbol + option['markercolor']) - markercolor.append(rgba) + colors = COLORS if option["markercolor"] is None else [option["markercolor"]] + + if len(X) <= min(len(MARKERS), len(colors)): + symbols_colors = zip(MARKERS[: len(X)], colors[: len(X)]) else: - # Define markers and colors using predefined list - marker = [] - markercolor = [] - for color in colorm: - for symbol in kind: - marker.append(symbol + color) - rgba = clr.to_rgb(color) + (alpha,) - markercolor.append(rgba) + symbols_colors = islice(cycle(product(MARKERS, colors)), len(X)) + max_cases = len(MARKERS) * len(colors) + if option["markercolor"] is None and len(X) > max_cases: + warnings.warn( + ( + f"You must introduce new markers and colors to plot more than {max_cases} cases." + "Markers and colors are defined using global variables MARKERS and COLORS" + ), + UserWarning, + ) + marker = [] + markercolor = [] + for symbol, color in symbols_colors: + marker.append(symbol + color) + markercolor.append(clr.to_rgba(color, option["alpha"])) return marker, markercolor