Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jbogaardt committed Aug 18, 2021
2 parents e3cd054 + b84a493 commit f6f78ed
Show file tree
Hide file tree
Showing 5 changed files with 784 additions and 740 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
os: ['ubuntu-latest'] #, 'macos-latest', 'windows-latest']
python-version: ['3.5', '3.6', '3.7', '3.8', '3.9']
python-version: ['3.9'] #['3.5', '3.6', '3.7', '3.8', '3.9']
steps:
- uses: actions/checkout@v1
- uses: conda-incubator/setup-miniconda@v2
Expand Down
28 changes: 19 additions & 9 deletions chainladder/core/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _repr_format(self, origin_as_datetime=False):
development.name = None
return pd.DataFrame(out, index=origin, columns=development)

def heatmap(self, cmap="RdBu", low=0, high=0, axis=0, subset=None):
def heatmap(self, cmap="coolwarm", low=0, high=0, axis=0, subset=None):
""" Color the background in a gradient according to the data in each
column (optionally row). Requires matplotlib
Expand All @@ -94,18 +94,28 @@ def heatmap(self, cmap="RdBu", low=0, high=0, axis=0, subset=None):
if (self.values.shape[0], self.values.shape[1]) == (1, 1):
data = self._repr_format()
fmt_str = self._get_format_str(data)
if len(self.ddims) > 1 and type(self.ddims[0]) is int:
data.columns = [["Development Lag"] * len(self.ddims), self.ddims]

axis = self._get_axis(axis)
default = (
data.style.format(fmt_str)
.background_gradient(
cmap=cmap, low=low, high=high, axis=axis, subset=subset

raw_rank = data.rank(axis=axis)
shape_size = data.shape[axis]
rank_size = data.rank(axis=axis).max(axis=axis)
gmap = (raw_rank-1).div(rank_size-1, axis=not axis)*(shape_size-1) + 1
gmap = gmap.replace(np.nan, (shape_size+1)/2)

default_output = (
data.style.format(fmt_str).background_gradient(
cmap=cmap,
low=low,
high=high,
axis=None,
subset=subset,
gmap=gmap
)
.render()
)
default = re.sub("<td.*nan.*td>", "<td></td>", default)
return HTML(default)
output_xnan = re.sub("<td.*nan.*td>", "<td></td>", default_output)
return HTML(output_xnan)
elif HTML is None:
raise ImportError("heatmap requires IPython")
else:
Expand Down
2 changes: 1 addition & 1 deletion docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ need to install this manually in your environment.

R -e "install.packages('ChainLadder', repo='http://cran.rstudio.com')";

Lastly, set up the python chainladder package in develop mode.
Lastly, set up the python chainladder package in development mode.

::

Expand Down
Loading

0 comments on commit f6f78ed

Please sign in to comment.