Skip to content

Commit

Permalink
Merge pull request #116 from Nixtla/fix/deprecate-mycolorpy
Browse files Browse the repository at this point in the history
[FIX] Deprecate mycolorpy dependency
  • Loading branch information
AzulGarza authored Nov 30, 2022
2 parents f4f7111 + 173bd50 commit 339131a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
3 changes: 1 addition & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ dependencies:
- numba
- pandas
- scikit-learn
- quadprog
- pip
- pip:
- nbdev
- mycolorpy
- quadprog
12 changes: 6 additions & 6 deletions hierarchicalforecast/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import numpy as np
import pandas as pd
from sklearn.preprocessing import OneHotEncoder
# from matplotlib import rcParams
from mycolorpy import colorlist as mcp

plt.rcParams['font.family'] = 'serif'

Expand Down Expand Up @@ -124,7 +122,8 @@ def plot_series(self,
df_plot = Y_df.loc[series].set_index('ds')
cols = models if models is not None else df_plot.columns
cols_wo_levels = [col for col in cols if ('lo' not in col and 'hi' not in col)]
cmap = mcp.gen_color('tab10', 10)[:len(cols_wo_levels)]
cmap = plt.cm.get_cmap("tab10", 10)
cmap = [cmap(i) for i in range(10)][:len(cols_wo_levels)]
cmap_dict = dict(zip(cols_wo_levels, cmap))
df_plot[cols_wo_levels].plot(ax=ax, linewidth=2, color=cmap)
if level is not None:
Expand All @@ -142,7 +141,7 @@ def plot_series(self,
df_plot.index,
df_plot[f'{col}-lo-{lv}'],
df_plot[f'{col}-hi-{lv}'],
alpha=-lv/50 + 2,
alpha=-lv/100 + 1,
color=cmap_dict[col],
label=f'{col}_level_{lv}'
)
Expand Down Expand Up @@ -177,7 +176,8 @@ def plot_hierarchically_linked_series(self,
fig, axs = plt.subplots(len(linked_series), 1, figsize=(20, 2 * len(linked_series)))
cols = models if models is not None else Y_df.drop(['ds'], axis=1)
cols_wo_levels = [col for col in cols if ('lo' not in col and 'hi' not in col)]
cmap = mcp.gen_color('tab10', 10)[:len(cols_wo_levels)]
cmap = plt.cm.get_cmap("tab10", 10)
cmap = [cmap(i) for i in range(10)][:len(cols_wo_levels)]
cmap_dict = dict(zip(cols_wo_levels, cmap))
for idx, series in enumerate(linked_series):
df_plot = Y_df.loc[[series]].set_index('ds')
Expand All @@ -197,7 +197,7 @@ def plot_hierarchically_linked_series(self,
df_plot.index,
df_plot[f'{col}-lo-{lv}'],
df_plot[f'{col}-hi-{lv}'],
alpha=-lv/50 + 2,
alpha=-lv/100 + 1,
color=cmap_dict[col],
label=f'{col}_level_{lv}'
)
Expand Down
14 changes: 8 additions & 6 deletions nbs/utils.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
"import numpy as np\n",
"import pandas as pd\n",
"from sklearn.preprocessing import OneHotEncoder\n",
"# from matplotlib import rcParams\n",
"from mycolorpy import colorlist as mcp\n",
"\n",
"plt.rcParams['font.family'] = 'serif'"
]
Expand Down Expand Up @@ -239,7 +237,8 @@
" df_plot = Y_df.loc[series].set_index('ds')\n",
" cols = models if models is not None else df_plot.columns\n",
" cols_wo_levels = [col for col in cols if ('lo' not in col and 'hi' not in col)]\n",
" cmap = mcp.gen_color('tab10', 10)[:len(cols_wo_levels)]\n",
" cmap = plt.cm.get_cmap(\"tab10\", 10)\n",
" cmap = [cmap(i) for i in range(10)][:len(cols_wo_levels)]\n",
" cmap_dict = dict(zip(cols_wo_levels, cmap))\n",
" df_plot[cols_wo_levels].plot(ax=ax, linewidth=2, color=cmap)\n",
" if level is not None:\n",
Expand All @@ -257,7 +256,7 @@
" df_plot.index, \n",
" df_plot[f'{col}-lo-{lv}'], \n",
" df_plot[f'{col}-hi-{lv}'],\n",
" alpha=-lv/50 + 2,\n",
" alpha=-lv/100 + 1,\n",
" color=cmap_dict[col],\n",
" label=f'{col}_level_{lv}'\n",
" )\n",
Expand Down Expand Up @@ -292,7 +291,8 @@
" fig, axs = plt.subplots(len(linked_series), 1, figsize=(20, 2 * len(linked_series)))\n",
" cols = models if models is not None else Y_df.drop(['ds'], axis=1)\n",
" cols_wo_levels = [col for col in cols if ('lo' not in col and 'hi' not in col)]\n",
" cmap = mcp.gen_color('tab10', 10)[:len(cols_wo_levels)]\n",
" cmap = plt.cm.get_cmap(\"tab10\", 10)\n",
" cmap = [cmap(i) for i in range(10)][:len(cols_wo_levels)]\n",
" cmap_dict = dict(zip(cols_wo_levels, cmap))\n",
" for idx, series in enumerate(linked_series):\n",
" df_plot = Y_df.loc[[series]].set_index('ds')\n",
Expand All @@ -312,7 +312,7 @@
" df_plot.index, \n",
" df_plot[f'{col}-lo-{lv}'], \n",
" df_plot[f'{col}-hi-{lv}'],\n",
" alpha=-lv/50 + 2,\n",
" alpha=-lv/100 + 1,\n",
" color=cmap_dict[col],\n",
" label=f'{col}_level_{lv}'\n",
" )\n",
Expand Down Expand Up @@ -459,6 +459,8 @@
"hier_df['Model'] = hier_df['y'] * 1.1\n",
"hier_df['Model-lo-80'] = hier_df['Model'] - 0.1 * hier_df['Model']\n",
"hier_df['Model-hi-80'] = hier_df['Model'] + 0.1 * hier_df['Model']\n",
"hier_df['Model-lo-90'] = hier_df['Model'] - 0.2 * hier_df['Model']\n",
"hier_df['Model-hi-90'] = hier_df['Model'] + 0.2 * hier_df['Model']\n",
"hplots.plot_series(\n",
" series='Australia', \n",
" Y_df=hier_df,\n",
Expand Down
4 changes: 2 additions & 2 deletions settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ language = English
custom_sidebar = True
license = apache2
status = 2
requirements = numpy numba pandas scikit-learn mycolorpy quadprog
dev_requirements = datasetsforecast statsforecast>=1.0.0 requests matplotlib
requirements = numpy numba pandas scikit-learn quadprog matplotlib
dev_requirements = datasetsforecast statsforecast>=1.0.0 requests
nbs_path = nbs
doc_path = _docs
recursive = True
Expand Down

0 comments on commit 339131a

Please sign in to comment.