1818LEGEND_COLOR = '#efefef'
1919PLOT_BGCOLOR = '#ededed'
2020ANNOT_RECT_COLOR = '#d0d0d0'
21- SUBPLOT_SPACING = 0.015
2221LEGEND_BORDER_WIDTH = 1
2322LEGEND_ANNOT_X = 1.05
2423LEGEND_ANNOT_Y = 0.5
@@ -72,7 +71,8 @@ def _legend_annotation(color_name):
7271 return legend_title
7372
7473
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 ):
7676 l = (1 - (num_of_lanes - 1 ) * SUBPLOT_SPACING ) / (num_of_lanes )
7777 if not flipped :
7878 xanchor = 'center'
@@ -189,8 +189,8 @@ def _facet_grid_color_categorical(df, x, y, facet_row, facet_col, color_name,
189189 colormap , num_of_rows , num_of_cols ,
190190 facet_row_labels , facet_col_labels ,
191191 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 ):
194194
195195 fig = make_subplots (rows = num_of_rows , cols = num_of_cols ,
196196 shared_xaxes = True , shared_yaxes = True ,
@@ -257,6 +257,7 @@ def _facet_grid_color_categorical(df, x, y, facet_row, facet_col, color_name,
257257 label ,
258258 num_of_rows - j if facet_row else j + 1 ,
259259 num_of_rows if facet_row else num_of_cols ,
260+ SUBPLOT_SPACING ,
260261 'row' if facet_row else 'col' ,
261262 flipped_rows )
262263 )
@@ -319,12 +320,14 @@ def _facet_grid_color_categorical(df, x, y, facet_row, facet_col, color_name,
319320 facet_col_labels , facet_col )
320321 annotations .append (
321322 _annotation_dict (label , col_count + 1 , num_of_cols ,
323+ SUBPLOT_SPACING ,
322324 row_col = 'col' , flipped = flipped_cols )
323325 )
324326 label = _return_label (row_values [row_count ],
325327 facet_row_labels , facet_row )
326328 annotations .append (
327329 _annotation_dict (label , num_of_rows - row_count , num_of_rows ,
330+ SUBPLOT_SPACING ,
328331 row_col = 'row' , flipped = flipped_rows )
329332 )
330333
@@ -339,7 +342,8 @@ def _facet_grid_color_numerical(df, x, y, facet_row, facet_col, color_name,
339342 num_of_cols , facet_row_labels ,
340343 facet_col_labels , trace_type ,
341344 flipped_rows , flipped_cols , show_boxes ,
342- marker_color , kwargs_trace , kwargs_marker ):
345+ SUBPLOT_SPACING , marker_color , kwargs_trace ,
346+ kwargs_marker ):
343347
344348 fig = make_subplots (rows = num_of_rows , cols = num_of_cols ,
345349 shared_xaxes = True , shared_yaxes = True ,
@@ -406,6 +410,7 @@ def _facet_grid_color_numerical(df, x, y, facet_row, facet_col, color_name,
406410 label ,
407411 num_of_rows - j if facet_row else j + 1 ,
408412 num_of_rows if facet_row else num_of_cols ,
413+ SUBPLOT_SPACING ,
409414 'row' if facet_row else 'col' ,
410415 flipped = flipped_rows )
411416 )
@@ -458,13 +463,14 @@ def _facet_grid_color_numerical(df, x, y, facet_row, facet_col, color_name,
458463 facet_col_labels , facet_col )
459464 annotations .append (
460465 _annotation_dict (label , col_count + 1 , num_of_cols ,
466+ SUBPLOT_SPACING ,
461467 row_col = 'col' , flipped = flipped_cols )
462468 )
463469 label = _return_label (row_values [row_count ],
464470 facet_row_labels , facet_row )
465471 annotations .append (
466472 _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 ,
468474 row_col = 'row' , flipped = flipped_rows )
469475 )
470476
@@ -477,7 +483,7 @@ def _facet_grid_color_numerical(df, x, y, facet_row, facet_col, color_name,
477483def _facet_grid (df , x , y , facet_row , facet_col , num_of_rows ,
478484 num_of_cols , facet_row_labels , facet_col_labels ,
479485 trace_type , flipped_rows , flipped_cols , show_boxes ,
480- marker_color , kwargs_trace , kwargs_marker ):
486+ SUBPLOT_SPACING , marker_color , kwargs_trace , kwargs_marker ):
481487
482488 fig = make_subplots (rows = num_of_rows , cols = num_of_cols ,
483489 shared_xaxes = True , shared_yaxes = True ,
@@ -541,6 +547,7 @@ def _facet_grid(df, x, y, facet_row, facet_col, num_of_rows,
541547 label ,
542548 num_of_rows - j if facet_row else j + 1 ,
543549 num_of_rows if facet_row else num_of_cols ,
550+ SUBPLOT_SPACING ,
544551 'row' if facet_row else 'col' ,
545552 flipped_rows
546553 )
@@ -581,15 +588,15 @@ def _facet_grid(df, x, y, facet_row, facet_col, num_of_rows,
581588 facet_col_labels ,
582589 facet_col )
583590 annotations .append (
584- _annotation_dict (label , col_count + 1 , num_of_cols ,
591+ _annotation_dict (label , col_count + 1 , num_of_cols , SUBPLOT_SPACING ,
585592 row_col = 'col' , flipped = flipped_cols )
586593 )
587594
588595 label = _return_label (row_values [row_count ],
589596 facet_row_labels ,
590597 facet_row )
591598 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 ,
593600 row_col = 'row' , flipped = flipped_rows )
594601 )
595602
@@ -762,7 +769,6 @@ def create_facet_grid(df, x=None, y=None, facet_row=None, facet_col=None,
762769 fig = ff.create_facet_grid(
763770 mtcars,
764771 x='wt',
765- y='mpg',
766772 facet_col='cyl',
767773 trace_type='histogram',
768774 )
@@ -814,17 +820,20 @@ def create_facet_grid(df, x=None, y=None, facet_row=None, facet_col=None,
814820 "'trace_type' must be in {}" .format (VALID_TRACE_TYPES )
815821 )
816822
823+ if trace_type == 'histogram' :
824+ SUBPLOT_SPACING = 0.06
825+ else :
826+ SUBPLOT_SPACING = 0.015
827+
817828 # seperate kwargs for marker and else
818829 if 'marker' in kwargs :
819- kwargs_marker = copy . copy ( kwargs ['marker' ])
830+ kwargs_marker = kwargs ['marker' ]
820831 else :
821832 kwargs_marker = {}
822833 marker_color = kwargs_marker .pop ('color' , None )
823834 kwargs .pop ('marker' , None )
824- kwargs_trace = copy . copy ( kwargs )
835+ kwargs_trace = kwargs
825836
826- print kwargs_marker
827- print kwargs_trace
828837 if 'size' not in kwargs_marker :
829838 if ggplot2 :
830839 kwargs_marker ['size' ] = 5
@@ -900,7 +909,7 @@ def create_facet_grid(df, x=None, y=None, facet_row=None, facet_col=None,
900909 df , x , y , facet_row , facet_col , color_name , colormap ,
901910 num_of_rows , num_of_cols , facet_row_labels , facet_col_labels ,
902911 trace_type , flipped_rows , flipped_cols , show_boxes ,
903- marker_color , kwargs_trace , kwargs_marker
912+ SUBPLOT_SPACING , marker_color , kwargs_trace , kwargs_marker
904913 )
905914
906915 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,
919928 df , x , y , facet_row , facet_col , color_name , colormap ,
920929 num_of_rows , num_of_cols , facet_row_labels ,
921930 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
924933 )
925934
926935 elif isinstance (colormap , list ):
@@ -931,8 +940,8 @@ def create_facet_grid(df, x=None, y=None, facet_row=None, facet_col=None,
931940 df , x , y , facet_row , facet_col , color_name ,
932941 colorscale_list , num_of_rows , num_of_cols ,
933942 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
936945 )
937946 elif isinstance (colormap , str ):
938947 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,
947956 df , x , y , facet_row , facet_col , color_name ,
948957 colorscale_list , num_of_rows , num_of_cols ,
949958 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
952961 )
953962 else :
954963 colorscale_list = colors .PLOTLY_SCALES ['Reds' ]
955964 fig = _facet_grid_color_numerical (
956965 df , x , y , facet_row , facet_col , color_name ,
957966 colorscale_list , num_of_rows , num_of_cols ,
958967 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
961970 )
962971
963972 else :
964973 fig = _facet_grid (
965974 df , x , y , facet_row , facet_col , num_of_rows , num_of_cols ,
966975 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
969978 )
970979
971980 if not height :
0 commit comments