Skip to content

Commit

Permalink
Support visualisations for nodes with samples from only one class.
Browse files Browse the repository at this point in the history
  • Loading branch information
tlapusan authored and parrt committed Apr 2, 2023
1 parent 89255de commit 8c15ccc
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions dtreeviz/trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import tempfile
from typing import Mapping, List, Callable

import matplotlib
import matplotlib.patches as patches
import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -1183,12 +1184,22 @@ def _class_split_viz(node: ShadowDecTreeNode,
histtype=histtype,
bins=bins,
label=class_names)

# Alter appearance of each bar
for patch in barcontainers:
for rect in patch.patches:
if isinstance(barcontainers[0], matplotlib.container.BarContainer):
for patch in barcontainers:
for rect in patch.patches:
rect.set_linewidth(.5)
rect.set_edgecolor(colors['rect_edge'])
ax.set_yticks([0, max([max(h) for h in hist])])
elif isinstance(barcontainers[0], matplotlib.patches.Rectangle):
# In case a node will contains samples from only one class.
for rect in barcontainers.patches:
rect.set_linewidth(.5)
rect.set_edgecolor(colors['rect_edge'])
ax.set_yticks([0, max([max(h) for h in hist])])
ax.set_yticks([0, max(hist)])



# set an empty space at the beginning and the end of the node visualisation for better clarity
bin_length = bins[1] - bins[0]
Expand Down

0 comments on commit 8c15ccc

Please sign in to comment.