Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitafbbfb8

Browse files
author
minjk-bl
committed
Edit Seaborn app not to auto-import on loading preview, add inner function _vp_seaborn_show_values() for preview code
1 parent2e5313c commitafbbfb8

File tree

3 files changed

+67
-6
lines changed

3 files changed

+67
-6
lines changed

‎js/com/com_Config.js‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,14 @@ define([
104104
'%matplotlib inline'
105105
]
106106
},
107-
{library:'seaborn',alias:'sns'}
107+
{library:'seaborn',alias:'sns'},
108+
{
109+
library:'plotly.express',alias:'px',
110+
include:[
111+
'from plotly.offline import init_notebook_mode',
112+
'init_notebook_mode(connected=True)'
113+
]
114+
}
108115
]
109116
}
110117

@@ -251,6 +258,7 @@ define([
251258
'fileNaviCommand.py',
252259
'pandasCommand.py',
253260
'variableCommand.py',
261+
'visualizationCommand.py',
254262
// 'userCommand.py'
255263
];
256264
letpromiseList=[];

‎js/m_visualize/Seaborn.js‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,8 @@ define([
280280
$(this.wrapSelector('#showValues')).on('change',function(){
281281
letchecked=$(this).prop('checked');
282282
if(checked===true){
283-
that.config.checkModules=['plt','sns','np','vp_seaborn_show_values'];
284283
$(that.wrapSelector('#showValuesPrecision')).attr('disabled',false);
285284
}else{
286-
that.config.checkModules=['plt','sns'];
287285
$(that.wrapSelector('#showValuesPrecision')).attr('disabled',true);
288286
}
289287
});
@@ -696,6 +694,9 @@ define([
696694
});
697695

698696
this.closeInnerPopup();
697+
698+
// load preview
699+
this.loadPreview();
699700
}
700701

701702
loadPreview(){
@@ -802,7 +803,19 @@ define([
802803
letconfig=this.chartConfig[chartType];
803804
letstate=JSON.parse(JSON.stringify(this.state));
804805

805-
if(preview&&useSampling){
806+
// set checkmodules
807+
if(preview===true){
808+
// no auto-import for preview
809+
this.config.checkModules=[];
810+
}else{
811+
if(showValues&&showValues===true){
812+
this.config.checkModules=['plt','sns','np','vp_seaborn_show_values'];
813+
}else{
814+
this.config.checkModules=['plt','sns'];
815+
}
816+
}
817+
818+
if(preview===true&&useSampling){
806819
// data sampling code for preview
807820
// convertedData = data + '.sample(n=' + sampleCount + ', random_state=0)';
808821
// convertedData = com_util.formatString('_vp_sample({0}, {1})', data, sampleCount);
@@ -965,7 +978,7 @@ define([
965978
chartCode.appendFormatLine("plt.grid({0})",gridCodeList.join(', '));
966979
}
967980

968-
if(preview){
981+
if(preview===true){
969982
// Ignore warning
970983
code.appendLine('import warnings');
971984
code.appendLine('with warnings.catch_warnings():');
@@ -978,7 +991,7 @@ define([
978991

979992
if(showValues&&showValues===true){
980993
code.appendLine('ax = '+generatedCode);
981-
code.append("vp_seaborn_show_values(ax");
994+
code.append("_vp_seaborn_show_values(ax");
982995
if(showValuesPrecision!==''){
983996
code.appendFormat(", precision={0}",showValuesPrecision);
984997
}

‎python/visualizationCommand.py‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
importnumpyas_vp_np
2+
def_vp_seaborn_show_values(axs,precision=1,space=0.01):
3+
"""
4+
Show values on Seaborn plots
5+
- inner function for showing preview on Seaborn app
6+
"""
7+
pstr='{:.'+str(precision)+'f}'
8+
9+
def_single(ax):
10+
# check orient
11+
orient='v'
12+
iflen(ax.patches)==1:
13+
# check if 0
14+
ifax.patches[0].get_x()==0:
15+
orient='h'
16+
else:
17+
# compare 0, 1 patches
18+
p0=ax.patches[0]
19+
p1=ax.patches[1]
20+
ifp0.get_x()==p1.get_x():
21+
orient='h'
22+
23+
iforient=='v':
24+
forpinax.patches:
25+
_x=p.get_x()+p.get_width()/2
26+
_y=p.get_y()+p.get_height()+ (p.get_height()*space)
27+
value=pstr.format(p.get_height())
28+
ax.text(_x,_y,value,ha='center')
29+
eliforient=='h':
30+
forpinax.patches:
31+
_x=p.get_x()+p.get_width()+ (space-0.01)
32+
_y=p.get_y()+p.get_height()/2
33+
value=pstr.format(p.get_width())
34+
ax.text(_x,_y,value,ha='left')
35+
36+
ifisinstance(axs,_vp_np.ndarray):
37+
foridx,axin_vp_np.ndenumerate(axs):
38+
_single(ax)
39+
else:
40+
_single(axs)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp