From 144db1cafcdbcdc23783f7a57a5a7290035a5807 Mon Sep 17 00:00:00 2001 From: Mattia Almansi Date: Wed, 5 Apr 2023 14:04:27 +0200 Subject: [PATCH 01/10] fix default markers --- skill_metrics/get_default_markers.py | 75 +++++++++++++++------------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/skill_metrics/get_default_markers.py b/skill_metrics/get_default_markers.py index bca622e..b4ce51b 100755 --- a/skill_metrics/get_default_markers.py +++ b/skill_metrics/get_default_markers.py @@ -1,18 +1,23 @@ +import warnings +from itertools import cycle, islice, product + import matplotlib.colors as clr +from matplotlib.lines import Line2D + def get_default_markers(X, option: dict) -> tuple[list, list]: - ''' + """ Provides a list of default markers and marker colors. - + Returns a list of 70 marker symbol & color combinations. INPUTS: X : x-coordinates of markers - option : dictionary containing option values. (Refer to + option : dictionary containing option values. (Refer to GET_TARGET_DIAGRAM_OPTIONS function for more information.) option['markercolor'] : single color to use for all markers option['markerlabel'] : labels for markers - + OUTPUTS: marker : list of marker symbols markercolor : list of marker colors @@ -23,39 +28,37 @@ 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) + kind = [] + for marker in Line2D.filled_markers: + if marker == ".": + # Too similar to "o" + continue + if marker.islower() and marker.upper() in Line2D.filled_markers: + # E.g., h and H are too similar + continue + kind.append(marker) + + if option["markercolor"] is None: + colorm = [color for color in clr.BASE_COLORS if color != "w"] 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) + colorm = [option["markercolor"]] + + max_cases = len(kind) * len(colorm) + if len(X) > max_cases: + warnings.warn( + ( + f"You must introduce new markers to plot more than {max_cases} cases." + "The marker character array need to be extended inside the code." + ), + UserWarning, + ) + marker = [] + markercolor = [] + for symbol, color in islice(cycle(product(kind, colorm)), len(X)): + marker.append(symbol + color) + rgba = clr.to_rgb(color) + (option["alpha"],) + markercolor.append(rgba) return marker, markercolor From 0e4aa8e41dd6ff293d16b4ba4e1eb9da6414747e Mon Sep 17 00:00:00 2001 From: Mattia Almansi Date: Wed, 5 Apr 2023 15:29:52 +0200 Subject: [PATCH 02/10] restore original --- skill_metrics/get_default_markers.py | 40 +++++++++++----------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/skill_metrics/get_default_markers.py b/skill_metrics/get_default_markers.py index b4ce51b..4a8cd05 100755 --- a/skill_metrics/get_default_markers.py +++ b/skill_metrics/get_default_markers.py @@ -2,7 +2,6 @@ from itertools import cycle, islice, product import matplotlib.colors as clr -from matplotlib.lines import Line2D def get_default_markers(X, option: dict) -> tuple[list, list]: @@ -29,35 +28,28 @@ def get_default_markers(X, option: dict) -> tuple[list, list]: Created on Mar 12, 2023 Revised on Mar 12, 2023 """ + # Define list of marker symbols and colros - kind = [] - for marker in Line2D.filled_markers: - if marker == ".": - # Too similar to "o" - continue - if marker.islower() and marker.upper() in Line2D.filled_markers: - # E.g., h and H are too similar - continue - kind.append(marker) + kind = ["+", "o", "x", "s", "d", "^", "v", "p", "h", "*"] + colorm = ["r", "b", "g", "c", "m", "y", "k"] - if option["markercolor"] is None: - colorm = [color for color in clr.BASE_COLORS if color != "w"] + if len(X) <= min(len(kind), len(colorm)): + iter_obj = zip(kind[: len(X)], colorm[: len(X)]) else: - colorm = [option["markercolor"]] - - max_cases = len(kind) * len(colorm) - if len(X) > max_cases: - warnings.warn( - ( - f"You must introduce new markers to plot more than {max_cases} cases." - "The marker character array need to be extended inside the code." - ), - UserWarning, - ) + max_cases = len(kind) * len(colorm) + iter_obj = islice(cycle(product(kind, colorm)), len(X)) + if len(X) > max_cases: + warnings.warn( + ( + f"You must introduce new markers to plot more than {max_cases} cases." + "The marker character array need to be extended inside the code." + ), + UserWarning, + ) marker = [] markercolor = [] - for symbol, color in islice(cycle(product(kind, colorm)), len(X)): + for symbol, color in iter_obj: marker.append(symbol + color) rgba = clr.to_rgb(color) + (option["alpha"],) markercolor.append(rgba) From 1fc804084f32c2a16e05fd3dcd67237ba47c20cd Mon Sep 17 00:00:00 2001 From: Mattia Almansi Date: Wed, 5 Apr 2023 15:33:22 +0200 Subject: [PATCH 03/10] better naming --- skill_metrics/get_default_markers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/skill_metrics/get_default_markers.py b/skill_metrics/get_default_markers.py index 4a8cd05..43e6b06 100755 --- a/skill_metrics/get_default_markers.py +++ b/skill_metrics/get_default_markers.py @@ -34,10 +34,10 @@ def get_default_markers(X, option: dict) -> tuple[list, list]: colorm = ["r", "b", "g", "c", "m", "y", "k"] if len(X) <= min(len(kind), len(colorm)): - iter_obj = zip(kind[: len(X)], colorm[: len(X)]) + symbols_colors = zip(kind[: len(X)], colorm[: len(X)]) else: max_cases = len(kind) * len(colorm) - iter_obj = islice(cycle(product(kind, colorm)), len(X)) + symbols_colors = islice(cycle(product(kind, colorm)), len(X)) if len(X) > max_cases: warnings.warn( ( @@ -49,7 +49,7 @@ def get_default_markers(X, option: dict) -> tuple[list, list]: marker = [] markercolor = [] - for symbol, color in iter_obj: + for symbol, color in symbols_colors: marker.append(symbol + color) rgba = clr.to_rgb(color) + (option["alpha"],) markercolor.append(rgba) From 92cd8481277aa0a301163bedea8f4dbe92396498 Mon Sep 17 00:00:00 2001 From: Mattia Almansi Date: Wed, 5 Apr 2023 15:40:48 +0200 Subject: [PATCH 04/10] use global variables --- skill_metrics/get_default_markers.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/skill_metrics/get_default_markers.py b/skill_metrics/get_default_markers.py index 43e6b06..26b9e7a 100755 --- a/skill_metrics/get_default_markers.py +++ b/skill_metrics/get_default_markers.py @@ -3,6 +3,10 @@ import matplotlib.colors as clr +# Define list of marker symbols and colros +KIND = ["+", "o", "x", "s", "d", "^", "v", "p", "h", "*"] +COLORM = ["r", "b", "g", "c", "m", "y", "k"] + def get_default_markers(X, option: dict) -> tuple[list, list]: """ @@ -29,20 +33,16 @@ def get_default_markers(X, option: dict) -> tuple[list, list]: Revised on Mar 12, 2023 """ - # Define list of marker symbols and colros - kind = ["+", "o", "x", "s", "d", "^", "v", "p", "h", "*"] - colorm = ["r", "b", "g", "c", "m", "y", "k"] - - if len(X) <= min(len(kind), len(colorm)): - symbols_colors = zip(kind[: len(X)], colorm[: len(X)]) + if len(X) <= min(len(KIND), len(COLORM)): + symbols_colors = zip(KIND[: len(X)], COLORM[: len(X)]) else: - max_cases = len(kind) * len(colorm) - symbols_colors = islice(cycle(product(kind, colorm)), len(X)) + max_cases = len(KIND) * len(COLORM) + symbols_colors = islice(cycle(product(KIND, COLORM)), len(X)) if len(X) > max_cases: warnings.warn( ( - f"You must introduce new markers to plot more than {max_cases} cases." - "The marker character array need to be extended inside the code." + f"You must introduce new markers and colors to plot more than {max_cases} cases." + "Markers and colors are defined using global variables KIND and COLORM" ), UserWarning, ) From d05dd2ee7c606002379eed4ecb5c5ded372ab816 Mon Sep 17 00:00:00 2001 From: Mattia Almansi Date: Wed, 5 Apr 2023 15:49:13 +0200 Subject: [PATCH 05/10] rename global variables --- skill_metrics/get_default_markers.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/skill_metrics/get_default_markers.py b/skill_metrics/get_default_markers.py index 26b9e7a..ba62ac9 100755 --- a/skill_metrics/get_default_markers.py +++ b/skill_metrics/get_default_markers.py @@ -4,8 +4,8 @@ import matplotlib.colors as clr # Define list of marker symbols and colros -KIND = ["+", "o", "x", "s", "d", "^", "v", "p", "h", "*"] -COLORM = ["r", "b", "g", "c", "m", "y", "k"] +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]: @@ -33,16 +33,16 @@ def get_default_markers(X, option: dict) -> tuple[list, list]: Revised on Mar 12, 2023 """ - if len(X) <= min(len(KIND), len(COLORM)): - symbols_colors = zip(KIND[: len(X)], COLORM[: len(X)]) + if len(X) <= min(len(MARKERS), len(COLORS)): + symbols_colors = zip(MARKERS[: len(X)], COLORS[: len(X)]) else: - max_cases = len(KIND) * len(COLORM) - symbols_colors = islice(cycle(product(KIND, COLORM)), len(X)) + max_cases = len(MARKERS) * len(COLORS) + symbols_colors = islice(cycle(product(MARKERS, COLORS)), len(X)) if 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 KIND and COLORM" + "Markers and colors are defined using global variables MARKERS and COLORS" ), UserWarning, ) From 2f46c006ba360fe0a3f39d4654585aeeab923d3e Mon Sep 17 00:00:00 2001 From: Mattia Almansi Date: Wed, 5 Apr 2023 17:09:40 +0200 Subject: [PATCH 06/10] restore infer from option --- skill_metrics/get_default_markers.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/skill_metrics/get_default_markers.py b/skill_metrics/get_default_markers.py index ba62ac9..878da8e 100755 --- a/skill_metrics/get_default_markers.py +++ b/skill_metrics/get_default_markers.py @@ -32,12 +32,14 @@ def get_default_markers(X, option: dict) -> tuple[list, list]: Created on Mar 12, 2023 Revised on Mar 12, 2023 """ + markers = MARKERS + 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)]) + if len(X) <= min(len(markers), len(colors)): + symbols_colors = zip(markers[: len(X)], colors[: len(X)]) else: - max_cases = len(MARKERS) * len(COLORS) - symbols_colors = islice(cycle(product(MARKERS, COLORS)), len(X)) + max_cases = len(markers) * len(colors) + symbols_colors = islice(cycle(product(markers, colors)), len(X)) if len(X) > max_cases: warnings.warn( ( From ca143d1cc081a4f8e89a57d9670c4857ab1c334c Mon Sep 17 00:00:00 2001 From: Mattia Almansi Date: Wed, 5 Apr 2023 17:43:39 +0200 Subject: [PATCH 07/10] reduce warnings --- skill_metrics/get_default_markers.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/skill_metrics/get_default_markers.py b/skill_metrics/get_default_markers.py index 878da8e..3a8c67b 100755 --- a/skill_metrics/get_default_markers.py +++ b/skill_metrics/get_default_markers.py @@ -32,15 +32,14 @@ def get_default_markers(X, option: dict) -> tuple[list, list]: Created on Mar 12, 2023 Revised on Mar 12, 2023 """ - markers = MARKERS 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)]) + if len(X) <= min(len(MARKERS), len(colors)): + symbols_colors = zip(MARKERS[: len(X)], colors[: len(X)]) else: - max_cases = len(markers) * len(colors) - symbols_colors = islice(cycle(product(markers, colors)), len(X)) - if len(X) > max_cases: + 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." From d5ab6fcf0426427a8c8171337f13afa9840d5e12 Mon Sep 17 00:00:00 2001 From: Mattia Almansi Date: Wed, 5 Apr 2023 19:46:18 +0200 Subject: [PATCH 08/10] tupo --- skill_metrics/get_default_markers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skill_metrics/get_default_markers.py b/skill_metrics/get_default_markers.py index 3a8c67b..0ae08ea 100755 --- a/skill_metrics/get_default_markers.py +++ b/skill_metrics/get_default_markers.py @@ -3,7 +3,7 @@ import matplotlib.colors as clr -# Define list of marker symbols and colros +# Define list of marker symbols and colors MARKERS = ["+", "o", "x", "s", "d", "^", "v", "p", "h", "*"] COLORS = ["r", "b", "g", "c", "m", "y", "k"] From da5a6bfb5acae4bf42a11571eb3e66ce6476369e Mon Sep 17 00:00:00 2001 From: Mattia Almansi Date: Wed, 5 Apr 2023 20:01:01 +0200 Subject: [PATCH 09/10] cleanup --- skill_metrics/get_default_markers.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/skill_metrics/get_default_markers.py b/skill_metrics/get_default_markers.py index 0ae08ea..96717fe 100755 --- a/skill_metrics/get_default_markers.py +++ b/skill_metrics/get_default_markers.py @@ -52,6 +52,5 @@ def get_default_markers(X, option: dict) -> tuple[list, list]: markercolor = [] for symbol, color in symbols_colors: marker.append(symbol + color) - rgba = clr.to_rgb(color) + (option["alpha"],) - markercolor.append(rgba) + markercolor.append(clr.to_rgba(color, option["alpha"])) return marker, markercolor From 15b2f129d2e39ecde33eb88d361012ec991d740a Mon Sep 17 00:00:00 2001 From: Mattia Almansi Date: Wed, 5 Apr 2023 20:18:44 +0200 Subject: [PATCH 10/10] unlint docstrings --- skill_metrics/get_default_markers.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/skill_metrics/get_default_markers.py b/skill_metrics/get_default_markers.py index 96717fe..7056ba2 100755 --- a/skill_metrics/get_default_markers.py +++ b/skill_metrics/get_default_markers.py @@ -9,18 +9,18 @@ def get_default_markers(X, option: dict) -> tuple[list, list]: - """ + ''' Provides a list of default markers and marker colors. - + Returns a list of 70 marker symbol & color combinations. INPUTS: X : x-coordinates of markers - option : dictionary containing option values. (Refer to + option : dictionary containing option values. (Refer to GET_TARGET_DIAGRAM_OPTIONS function for more information.) option['markercolor'] : single color to use for all markers option['markerlabel'] : labels for markers - + OUTPUTS: marker : list of marker symbols markercolor : list of marker colors @@ -31,7 +31,7 @@ def get_default_markers(X, option: dict) -> tuple[list, list]: Created on Mar 12, 2023 Revised on Mar 12, 2023 - """ + ''' colors = COLORS if option["markercolor"] is None else [option["markercolor"]] if len(X) <= min(len(MARKERS), len(colors)):