Skip to content

Commit b44bfff

Browse files
author
minjk-bl
committed
Add show values inner function
1 parent 7ddc806 commit b44bfff

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

python/userCommand.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,42 @@ def vp_plot_feature_importances(model, X_train=None, sort=False):
8989
_vp_plt.xlabel('Feature importance Percentage')
9090
_vp_plt.ylabel('Features')
9191

92-
_vp_plt.show()
92+
_vp_plt.show()
93+
######
94+
# Visual Python: Visualization > Seaborn
95+
######
96+
def vp_seaborn_show_values(axs, precision=1, space=0.01):
97+
pstr = '{:.' + str(precision) + 'f}'
98+
99+
def _single(ax):
100+
# check orient
101+
orient = 'v'
102+
if len(ax.patches) == 1:
103+
# check if 0
104+
if ax.patches[0].get_x() == 0:
105+
orient = 'h'
106+
else:
107+
# compare 0, 1 patches
108+
p0 = ax.patches[0]
109+
p1 = ax.patches[1]
110+
if p0.get_x() == p1.get_x():
111+
orient = 'h'
112+
113+
if orient == 'v':
114+
for p in ax.patches:
115+
_x = p.get_x() + p.get_width() / 2
116+
_y = p.get_y() + p.get_height() + (p.get_height()*space)
117+
value = pstr.format(p.get_height())
118+
ax.text(_x, _y, value, ha='center')
119+
elif orient == 'h':
120+
for p in ax.patches:
121+
_x = p.get_x() + p.get_width() + (space - 0.01)
122+
_y = p.get_y() + p.get_height() / 2
123+
value = pstr.format(p.get_width())
124+
ax.text(_x, _y, value, ha='left')
125+
126+
if isinstance(axs, _vp_np.ndarray):
127+
for idx, ax in _vp_np.ndenumerate(axs):
128+
_single(ax)
129+
else:
130+
_single(axs)

0 commit comments

Comments
 (0)