Skip to content

Commit 7ddc806

Browse files
author
minjk-bl
committed
Add show values option for barplot/histplot/countplot on Seaborn
1 parent 9ca01bf commit 7ddc806

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

html/m_visualize/seaborn.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@
114114
<!-- Auto-create -->
115115
</select>
116116
</div>
117+
<div class="vp-grid-box sb-option">
118+
<label><input type="checkbox" id="showValues" class="vp-state"/><span>Show values</span></label>
119+
</div>
117120
</div>
118121
<label for="userOption" class="vp-bold">User Option</label>
119122
<input type="text" id="userOption" class="vp-input vp-state wp100" placeholder="key=value, ..."/>

js/m_visualize/Seaborn.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ define([
4848
bins: '',
4949
kde: '',
5050
stat: '',
51+
showValues: false,
5152
// axes options
5253
x_limit_from: '',
5354
x_limit_to: '',
@@ -190,6 +191,10 @@ define([
190191
$(that.wrapSelector('#bins')).closest('.sb-option').show();
191192
$(that.wrapSelector('#kde')).closest('.sb-option').show();
192193
$(that.wrapSelector('#stat')).closest('.sb-option').show();
194+
} else if (chartType == 'barplot') {
195+
$(that.wrapSelector('#showValues')).closest('.sb-option').show();
196+
} else if (chartType == 'countplot') {
197+
$(that.wrapSelector('#showValues')).closest('.sb-option').show();
193198
}
194199
});
195200

@@ -403,6 +408,10 @@ define([
403408
$(page).find('#bins').closest('.sb-option').show();
404409
$(page).find('#kde').closest('.sb-option').show();
405410
$(page).find('#stat').closest('.sb-option').show();
411+
} else if (this.state.chartType == 'barplot') {
412+
$(page).find('#showValues').closest('.sb-option').show();
413+
} else if (this.state.chartType == 'countplot') {
414+
$(page).find('#showValues').closest('.sb-option').show();
406415
}
407416

408417
//================================================================
@@ -696,7 +705,7 @@ define([
696705

697706
generateCode(preview=false) {
698707
let {
699-
chartType, data, x, y, hue, setXY, userOption='',
708+
chartType, data, x, y, setXY, hue, kde, stat, showValues, userOption='',
700709
x_limit_from, x_limit_to, y_limit_from, y_limit_to,
701710
xticks, xticks_label, xticks_rotate, removeXticks,
702711
yticks, yticks_label, yticks_rotate, removeYticks,
@@ -721,6 +730,9 @@ define([
721730
// TODO: marker to seaborn argument (ex. marker='+' / markers={'Lunch':'s', 'Dinner':'X'})
722731
etcOptionCode.push(com_util.formatString("marker='{0}'", markerStyle));
723732
}
733+
if (showValues === true && chartType === 'barplot') {
734+
etcOptionCode.push('ci=None');
735+
}
724736

725737
// add user option
726738
if (userOption != '') {
@@ -837,10 +849,20 @@ define([
837849
let defaultHeight = 6;
838850
code.appendFormatLine('plt.figure(figsize=({0}, {1}))', defaultWidth, defaultHeight);
839851

840-
code.appendLine(generatedCode);
852+
if (showValues && showValues === true) {
853+
code.appendLine('ax = ' + generatedCode);
854+
code.appendLine("vp_seaborn_show_values(ax)");
855+
} else {
856+
code.appendLine(generatedCode);
857+
}
841858
code.appendLine(chartCode.toString());
842859
} else {
843-
code.appendLine(generatedCode);
860+
if (showValues && showValues === true) {
861+
code.appendLine('ax = ' + generatedCode);
862+
code.appendLine("vp_seaborn_show_values(ax)");
863+
} else {
864+
code.appendLine(generatedCode);
865+
}
844866
if (chartCode.length > 0) {
845867
code.append(chartCode.toString());
846868
}

0 commit comments

Comments
 (0)