Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default markers #38

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 27 additions & 32 deletions skill_metrics/get_default_markers.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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