25
25
THRES_FOR_FLIPPED_FACET_TITLES = 10
26
26
GRID_WIDTH = 1
27
27
28
+ VALID_TRACE_TYPES = ['scatter' , 'scattergl' , 'histogram' ]
28
29
29
30
CUSTOM_LABEL_ERROR = (
30
31
"If you are using a dictionary for custom labels for the facet row/col, "
@@ -176,7 +177,7 @@ def _add_shapes_to_fig(fig, annot_rect_color, flipped_rows=False,
176
177
def _facet_grid_color_categorical (df , x , y , facet_row , facet_col , color_name ,
177
178
colormap , num_of_rows ,
178
179
num_of_cols , facet_row_labels ,
179
- facet_col_labels , trace_type ,
180
+ facet_col_labels , temp_trace ,
180
181
flipped_rows , flipped_cols , show_boxes ,
181
182
marker_color , kwargs_trace , kwargs_marker ):
182
183
@@ -193,7 +194,7 @@ def _facet_grid_color_categorical(df, x, y, facet_row, facet_col, color_name,
193
194
x = group [1 ][x ],
194
195
y = group [1 ][y ],
195
196
mode = 'markers' ,
196
- type = trace_type ,
197
+ type = temp_trace ,
197
198
name = group [0 ],
198
199
marker = dict (
199
200
color = colormap [group [0 ]],
@@ -214,7 +215,7 @@ def _facet_grid_color_categorical(df, x, y, facet_row, facet_col, color_name,
214
215
x = data_by_color [x ],
215
216
y = data_by_color [y ],
216
217
mode = 'markers' ,
217
- type = trace_type ,
218
+ type = temp_trace ,
218
219
name = color_val ,
219
220
marker = dict (
220
221
color = colormap [color_val ],
@@ -265,7 +266,7 @@ def _facet_grid_color_categorical(df, x, y, facet_row, facet_col, color_name,
265
266
x = group_filtered [x ],
266
267
y = group_filtered [y ],
267
268
mode = 'markers' ,
268
- type = trace_type ,
269
+ type = temp_trace ,
269
270
name = color_val ,
270
271
marker = dict (
271
272
color = colormap [color_val ],
@@ -278,7 +279,7 @@ def _facet_grid_color_categorical(df, x, y, facet_row, facet_col, color_name,
278
279
x = group [x ],
279
280
y = group [y ],
280
281
mode = 'markers' ,
281
- type = trace_type ,
282
+ type = temp_trace ,
282
283
name = color_val ,
283
284
marker = dict (
284
285
color = colormap [color_val ],
@@ -311,7 +312,7 @@ def _facet_grid_color_categorical(df, x, y, facet_row, facet_col, color_name,
311
312
def _facet_grid_color_numerical (df , x , y , facet_row , facet_col , color_name ,
312
313
colormap , num_of_rows ,
313
314
num_of_cols , facet_row_labels ,
314
- facet_col_labels , trace_type ,
315
+ facet_col_labels , temp_trace ,
315
316
flipped_rows , flipped_cols , show_boxes ,
316
317
marker_color , kwargs_trace , kwargs_marker ):
317
318
@@ -326,7 +327,7 @@ def _facet_grid_color_numerical(df, x, y, facet_row, facet_col, color_name,
326
327
x = df [x ],
327
328
y = df [y ],
328
329
mode = 'markers' ,
329
- type = trace_type ,
330
+ type = temp_trace ,
330
331
marker = dict (
331
332
color = df [color_name ],
332
333
colorscale = colormap ,
@@ -346,7 +347,7 @@ def _facet_grid_color_numerical(df, x, y, facet_row, facet_col, color_name,
346
347
x = group [1 ][x ],
347
348
y = group [1 ][y ],
348
349
mode = 'markers' ,
349
- type = trace_type ,
350
+ type = temp_trace ,
350
351
marker = dict (
351
352
color = df [color_name ],
352
353
colorscale = colormap ,
@@ -396,7 +397,7 @@ def _facet_grid_color_numerical(df, x, y, facet_row, facet_col, color_name,
396
397
x = group [x ],
397
398
y = group [y ],
398
399
mode = 'markers' ,
399
- type = trace_type ,
400
+ type = temp_trace ,
400
401
marker = dict (
401
402
color = df [color_name ],
402
403
colorscale = colormap ,
@@ -411,7 +412,7 @@ def _facet_grid_color_numerical(df, x, y, facet_row, facet_col, color_name,
411
412
x = group [x ],
412
413
y = group [y ],
413
414
mode = 'markers' ,
414
- type = trace_type ,
415
+ type = temp_trace ,
415
416
showlegend = False ,
416
417
** kwargs
417
418
)
@@ -439,7 +440,7 @@ def _facet_grid_color_numerical(df, x, y, facet_row, facet_col, color_name,
439
440
440
441
def _facet_grid (df , x , y , facet_row , facet_col , num_of_rows ,
441
442
num_of_cols , facet_row_labels , facet_col_labels ,
442
- trace_type , flipped_rows , flipped_cols , show_boxes ,
443
+ temp_trace , flipped_rows , flipped_cols , show_boxes ,
443
444
marker_color , kwargs_trace , kwargs_marker ):
444
445
445
446
fig = make_subplots (rows = num_of_rows , cols = num_of_cols ,
@@ -452,7 +453,7 @@ def _facet_grid(df, x, y, facet_row, facet_col, num_of_rows,
452
453
x = df [x ],
453
454
y = df [y ],
454
455
mode = 'markers' ,
455
- type = trace_type ,
456
+ type = temp_trace ,
456
457
marker = dict (
457
458
color = marker_color ,
458
459
** kwargs_marker
@@ -470,7 +471,7 @@ def _facet_grid(df, x, y, facet_row, facet_col, num_of_rows,
470
471
x = group [1 ][x ],
471
472
y = group [1 ][y ],
472
473
mode = 'markers' ,
473
- type = trace_type ,
474
+ type = temp_trace ,
474
475
marker = dict (
475
476
color = marker_color ,
476
477
** kwargs_marker
@@ -514,7 +515,7 @@ def _facet_grid(df, x, y, facet_row, facet_col, num_of_rows,
514
515
x = group [x ],
515
516
y = group [y ],
516
517
mode = 'markers' ,
517
- type = trace_type ,
518
+ type = temp_trace ,
518
519
marker = dict (
519
520
color = marker_color ,
520
521
** kwargs_marker
@@ -581,7 +582,7 @@ def create_facet_grid(df, x, y, facet_row=None, facet_col=None,
581
582
:param (int) height: the height of the facet grid figure.
582
583
:param (int) width: the width of the facet grid figure.
583
584
:param (str) trace_type: decides the type of plot to appear in the
584
- facet grid. The options are 'scatter' and 'scattergl '.
585
+ facet grid. The options are 'scatter', 'scattergl' and 'histogram '.
585
586
Default = 'scatter'.
586
587
:param (str) scales: determines if axes have fixed ranges or not. Valid
587
588
settings are 'fixed' (all axes fixed), 'free_x' (x axis free only),
@@ -726,11 +727,13 @@ def create_facet_grid(df, x, y, facet_row=None, facet_col=None,
726
727
"'scales' must be set to 'fixed', 'free_x', 'free_y' and 'free'."
727
728
)
728
729
729
- if trace_type not in [ 'scatter' , 'scattergl' ] :
730
+ if trace_type not in VALID_TRACE_TYPES :
730
731
raise exceptions .PlotlyError (
731
- "'trace_type' must be 'scatter' or 'scattergl'."
732
+ "'trace_type' must be in {}" . format ( VALID_TRACE_TYPES )
732
733
)
733
734
735
+ temp_trace = 'scatter' if (trace_type == 'histogram' ) else trace_type
736
+
734
737
# seperate kwargs for marker and else
735
738
if 'marker' in kwargs :
736
739
kwargs_marker = kwargs ['marker' ]
@@ -808,7 +811,7 @@ def create_facet_grid(df, x, y, facet_row=None, facet_col=None,
808
811
fig = _facet_grid_color_categorical (
809
812
df , x , y , facet_row , facet_col , color_name , colormap ,
810
813
num_of_rows , num_of_cols , facet_row_labels , facet_col_labels ,
811
- trace_type , flipped_rows , flipped_cols , show_boxes ,
814
+ temp_trace , flipped_rows , flipped_cols , show_boxes ,
812
815
marker_color , kwargs_trace , kwargs_marker
813
816
)
814
817
@@ -827,7 +830,7 @@ def create_facet_grid(df, x, y, facet_row=None, facet_col=None,
827
830
fig = _facet_grid_color_categorical (
828
831
df , x , y , facet_row , facet_col , color_name , colormap ,
829
832
num_of_rows , num_of_cols , facet_row_labels ,
830
- facet_col_labels , trace_type , flipped_rows ,
833
+ facet_col_labels , temp_trace , flipped_rows ,
831
834
flipped_cols , show_boxes , marker_color , kwargs_trace ,
832
835
kwargs_marker
833
836
)
@@ -839,7 +842,7 @@ def create_facet_grid(df, x, y, facet_row=None, facet_col=None,
839
842
fig = _facet_grid_color_numerical (
840
843
df , x , y , facet_row , facet_col , color_name ,
841
844
colorscale_list , num_of_rows , num_of_cols ,
842
- facet_row_labels , facet_col_labels , trace_type ,
845
+ facet_row_labels , facet_col_labels , temp_trace ,
843
846
flipped_rows , flipped_cols , show_boxes , marker_color ,
844
847
kwargs_trace , kwargs_marker
845
848
)
@@ -855,7 +858,7 @@ def create_facet_grid(df, x, y, facet_row=None, facet_col=None,
855
858
fig = _facet_grid_color_numerical (
856
859
df , x , y , facet_row , facet_col , color_name ,
857
860
colorscale_list , num_of_rows , num_of_cols ,
858
- facet_row_labels , facet_col_labels , trace_type ,
861
+ facet_row_labels , facet_col_labels , temp_trace ,
859
862
flipped_rows , flipped_cols , show_boxes , marker_color ,
860
863
kwargs_trace , kwargs_marker
861
864
)
@@ -864,15 +867,15 @@ def create_facet_grid(df, x, y, facet_row=None, facet_col=None,
864
867
fig = _facet_grid_color_numerical (
865
868
df , x , y , facet_row , facet_col , color_name ,
866
869
colorscale_list , num_of_rows , num_of_cols ,
867
- facet_row_labels , facet_col_labels , trace_type ,
870
+ facet_row_labels , facet_col_labels , temp_trace ,
868
871
flipped_rows , flipped_cols , show_boxes , marker_color ,
869
872
kwargs_trace , kwargs_marker
870
873
)
871
874
872
875
else :
873
876
fig = _facet_grid (
874
877
df , x , y , facet_row , facet_col , num_of_rows , num_of_cols ,
875
- facet_row_labels , facet_col_labels , trace_type , flipped_rows ,
878
+ facet_row_labels , facet_col_labels , temp_trace , flipped_rows ,
876
879
flipped_cols , show_boxes , marker_color , kwargs_trace ,
877
880
kwargs_marker
878
881
)
@@ -1012,4 +1015,10 @@ def create_facet_grid(df, x, y, facet_row=None, facet_col=None,
1012
1015
if '{}axis' .format (x_y ) in key and range_are_numbers :
1013
1016
fig ['layout' ][key ]['range' ] = [min_range , max_range ]
1014
1017
1018
+ if trace_type == 'histogram' :
1019
+ for trace in fig ['data' ]:
1020
+ trace ['type' ] = trace_type
1021
+ del trace ['marker' ]['size' ]
1022
+ del trace ['mode' ]
1023
+
1015
1024
return fig
0 commit comments