18
18
LEGEND_COLOR = '#efefef'
19
19
PLOT_BGCOLOR = '#ededed'
20
20
ANNOT_RECT_COLOR = '#d0d0d0'
21
- SUBPLOT_SPACING = 0.015
22
21
LEGEND_BORDER_WIDTH = 1
23
22
LEGEND_ANNOT_X = 1.05
24
23
LEGEND_ANNOT_Y = 0.5
@@ -72,7 +71,8 @@ def _legend_annotation(color_name):
72
71
return legend_title
73
72
74
73
75
- def _annotation_dict (text , lane , num_of_lanes , row_col = 'col' , flipped = True ):
74
+ def _annotation_dict (text , lane , num_of_lanes , SUBPLOT_SPACING , row_col = 'col' ,
75
+ flipped = True ):
76
76
l = (1 - (num_of_lanes - 1 ) * SUBPLOT_SPACING ) / (num_of_lanes )
77
77
if not flipped :
78
78
xanchor = 'center'
@@ -189,8 +189,8 @@ def _facet_grid_color_categorical(df, x, y, facet_row, facet_col, color_name,
189
189
colormap , num_of_rows , num_of_cols ,
190
190
facet_row_labels , facet_col_labels ,
191
191
trace_type , flipped_rows , flipped_cols ,
192
- show_boxes , marker_color , kwargs_trace ,
193
- kwargs_marker ):
192
+ show_boxes , SUBPLOT_SPACING , marker_color ,
193
+ kwargs_trace , kwargs_marker ):
194
194
195
195
fig = make_subplots (rows = num_of_rows , cols = num_of_cols ,
196
196
shared_xaxes = True , shared_yaxes = True ,
@@ -257,6 +257,7 @@ def _facet_grid_color_categorical(df, x, y, facet_row, facet_col, color_name,
257
257
label ,
258
258
num_of_rows - j if facet_row else j + 1 ,
259
259
num_of_rows if facet_row else num_of_cols ,
260
+ SUBPLOT_SPACING ,
260
261
'row' if facet_row else 'col' ,
261
262
flipped_rows )
262
263
)
@@ -319,12 +320,14 @@ def _facet_grid_color_categorical(df, x, y, facet_row, facet_col, color_name,
319
320
facet_col_labels , facet_col )
320
321
annotations .append (
321
322
_annotation_dict (label , col_count + 1 , num_of_cols ,
323
+ SUBPLOT_SPACING ,
322
324
row_col = 'col' , flipped = flipped_cols )
323
325
)
324
326
label = _return_label (row_values [row_count ],
325
327
facet_row_labels , facet_row )
326
328
annotations .append (
327
329
_annotation_dict (label , num_of_rows - row_count , num_of_rows ,
330
+ SUBPLOT_SPACING ,
328
331
row_col = 'row' , flipped = flipped_rows )
329
332
)
330
333
@@ -339,7 +342,8 @@ def _facet_grid_color_numerical(df, x, y, facet_row, facet_col, color_name,
339
342
num_of_cols , facet_row_labels ,
340
343
facet_col_labels , trace_type ,
341
344
flipped_rows , flipped_cols , show_boxes ,
342
- marker_color , kwargs_trace , kwargs_marker ):
345
+ SUBPLOT_SPACING , marker_color , kwargs_trace ,
346
+ kwargs_marker ):
343
347
344
348
fig = make_subplots (rows = num_of_rows , cols = num_of_cols ,
345
349
shared_xaxes = True , shared_yaxes = True ,
@@ -406,6 +410,7 @@ def _facet_grid_color_numerical(df, x, y, facet_row, facet_col, color_name,
406
410
label ,
407
411
num_of_rows - j if facet_row else j + 1 ,
408
412
num_of_rows if facet_row else num_of_cols ,
413
+ SUBPLOT_SPACING ,
409
414
'row' if facet_row else 'col' ,
410
415
flipped = flipped_rows )
411
416
)
@@ -458,13 +463,14 @@ def _facet_grid_color_numerical(df, x, y, facet_row, facet_col, color_name,
458
463
facet_col_labels , facet_col )
459
464
annotations .append (
460
465
_annotation_dict (label , col_count + 1 , num_of_cols ,
466
+ SUBPLOT_SPACING ,
461
467
row_col = 'col' , flipped = flipped_cols )
462
468
)
463
469
label = _return_label (row_values [row_count ],
464
470
facet_row_labels , facet_row )
465
471
annotations .append (
466
472
_annotation_dict (row_values [row_count ],
467
- num_of_rows - row_count , num_of_rows ,
473
+ num_of_rows - row_count , num_of_rows , SUBPLOT_SPACING ,
468
474
row_col = 'row' , flipped = flipped_rows )
469
475
)
470
476
@@ -477,7 +483,7 @@ def _facet_grid_color_numerical(df, x, y, facet_row, facet_col, color_name,
477
483
def _facet_grid (df , x , y , facet_row , facet_col , num_of_rows ,
478
484
num_of_cols , facet_row_labels , facet_col_labels ,
479
485
trace_type , flipped_rows , flipped_cols , show_boxes ,
480
- marker_color , kwargs_trace , kwargs_marker ):
486
+ SUBPLOT_SPACING , marker_color , kwargs_trace , kwargs_marker ):
481
487
482
488
fig = make_subplots (rows = num_of_rows , cols = num_of_cols ,
483
489
shared_xaxes = True , shared_yaxes = True ,
@@ -541,6 +547,7 @@ def _facet_grid(df, x, y, facet_row, facet_col, num_of_rows,
541
547
label ,
542
548
num_of_rows - j if facet_row else j + 1 ,
543
549
num_of_rows if facet_row else num_of_cols ,
550
+ SUBPLOT_SPACING ,
544
551
'row' if facet_row else 'col' ,
545
552
flipped_rows
546
553
)
@@ -581,15 +588,15 @@ def _facet_grid(df, x, y, facet_row, facet_col, num_of_rows,
581
588
facet_col_labels ,
582
589
facet_col )
583
590
annotations .append (
584
- _annotation_dict (label , col_count + 1 , num_of_cols ,
591
+ _annotation_dict (label , col_count + 1 , num_of_cols , SUBPLOT_SPACING ,
585
592
row_col = 'col' , flipped = flipped_cols )
586
593
)
587
594
588
595
label = _return_label (row_values [row_count ],
589
596
facet_row_labels ,
590
597
facet_row )
591
598
annotations .append (
592
- _annotation_dict (label , num_of_rows - row_count , num_of_rows ,
599
+ _annotation_dict (label , num_of_rows - row_count , num_of_rows , SUBPLOT_SPACING ,
593
600
row_col = 'row' , flipped = flipped_rows )
594
601
)
595
602
@@ -762,7 +769,6 @@ def create_facet_grid(df, x=None, y=None, facet_row=None, facet_col=None,
762
769
fig = ff.create_facet_grid(
763
770
mtcars,
764
771
x='wt',
765
- y='mpg',
766
772
facet_col='cyl',
767
773
trace_type='histogram',
768
774
)
@@ -814,17 +820,20 @@ def create_facet_grid(df, x=None, y=None, facet_row=None, facet_col=None,
814
820
"'trace_type' must be in {}" .format (VALID_TRACE_TYPES )
815
821
)
816
822
823
+ if trace_type == 'histogram' :
824
+ SUBPLOT_SPACING = 0.06
825
+ else :
826
+ SUBPLOT_SPACING = 0.015
827
+
817
828
# seperate kwargs for marker and else
818
829
if 'marker' in kwargs :
819
- kwargs_marker = copy . copy ( kwargs ['marker' ])
830
+ kwargs_marker = kwargs ['marker' ]
820
831
else :
821
832
kwargs_marker = {}
822
833
marker_color = kwargs_marker .pop ('color' , None )
823
834
kwargs .pop ('marker' , None )
824
- kwargs_trace = copy . copy ( kwargs )
835
+ kwargs_trace = kwargs
825
836
826
- print kwargs_marker
827
- print kwargs_trace
828
837
if 'size' not in kwargs_marker :
829
838
if ggplot2 :
830
839
kwargs_marker ['size' ] = 5
@@ -900,7 +909,7 @@ def create_facet_grid(df, x=None, y=None, facet_row=None, facet_col=None,
900
909
df , x , y , facet_row , facet_col , color_name , colormap ,
901
910
num_of_rows , num_of_cols , facet_row_labels , facet_col_labels ,
902
911
trace_type , flipped_rows , flipped_cols , show_boxes ,
903
- marker_color , kwargs_trace , kwargs_marker
912
+ SUBPLOT_SPACING , marker_color , kwargs_trace , kwargs_marker
904
913
)
905
914
906
915
elif isinstance (df [color_name ][0 ], Number ):
@@ -919,8 +928,8 @@ def create_facet_grid(df, x=None, y=None, facet_row=None, facet_col=None,
919
928
df , x , y , facet_row , facet_col , color_name , colormap ,
920
929
num_of_rows , num_of_cols , facet_row_labels ,
921
930
facet_col_labels , trace_type , flipped_rows ,
922
- flipped_cols , show_boxes , marker_color , kwargs_trace ,
923
- kwargs_marker
931
+ flipped_cols , show_boxes , SUBPLOT_SPACING , marker_color ,
932
+ kwargs_trace , kwargs_marker
924
933
)
925
934
926
935
elif isinstance (colormap , list ):
@@ -931,8 +940,8 @@ def create_facet_grid(df, x=None, y=None, facet_row=None, facet_col=None,
931
940
df , x , y , facet_row , facet_col , color_name ,
932
941
colorscale_list , num_of_rows , num_of_cols ,
933
942
facet_row_labels , facet_col_labels , trace_type ,
934
- flipped_rows , flipped_cols , show_boxes , marker_color ,
935
- kwargs_trace , kwargs_marker
943
+ flipped_rows , flipped_cols , show_boxes , SUBPLOT_SPACING ,
944
+ marker_color , kwargs_trace , kwargs_marker
936
945
)
937
946
elif isinstance (colormap , str ):
938
947
if colormap in colors .PLOTLY_SCALES .keys ():
@@ -947,25 +956,25 @@ def create_facet_grid(df, x=None, y=None, facet_row=None, facet_col=None,
947
956
df , x , y , facet_row , facet_col , color_name ,
948
957
colorscale_list , num_of_rows , num_of_cols ,
949
958
facet_row_labels , facet_col_labels , trace_type ,
950
- flipped_rows , flipped_cols , show_boxes , marker_color ,
951
- kwargs_trace , kwargs_marker
959
+ flipped_rows , flipped_cols , show_boxes , SUBPLOT_SPACING ,
960
+ marker_color , kwargs_trace , kwargs_marker
952
961
)
953
962
else :
954
963
colorscale_list = colors .PLOTLY_SCALES ['Reds' ]
955
964
fig = _facet_grid_color_numerical (
956
965
df , x , y , facet_row , facet_col , color_name ,
957
966
colorscale_list , num_of_rows , num_of_cols ,
958
967
facet_row_labels , facet_col_labels , trace_type ,
959
- flipped_rows , flipped_cols , show_boxes , marker_color ,
960
- kwargs_trace , kwargs_marker
968
+ flipped_rows , flipped_cols , show_boxes , SUBPLOT_SPACING ,
969
+ marker_color , kwargs_trace , kwargs_marker
961
970
)
962
971
963
972
else :
964
973
fig = _facet_grid (
965
974
df , x , y , facet_row , facet_col , num_of_rows , num_of_cols ,
966
975
facet_row_labels , facet_col_labels , trace_type , flipped_rows ,
967
- flipped_cols , show_boxes , marker_color , kwargs_trace ,
968
- kwargs_marker
976
+ flipped_cols , show_boxes , SUBPLOT_SPACING , marker_color ,
977
+ kwargs_trace , kwargs_marker
969
978
)
970
979
971
980
if not height :
0 commit comments