-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
added histogram to facet_grid #776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
ccc92da
bda26e1
3be914a
236e9a7
37d576d
1e355b1
180e0b7
483b487
5273f2d
af965d0
5e0acc2
788dcf9
e532d3e
8cd0de1
1ff4b5f
c99c0e7
2e7fecb
1b0e434
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
THRES_FOR_FLIPPED_FACET_TITLES = 10 | ||
GRID_WIDTH = 1 | ||
|
||
VALID_TRACE_TYPES = ['scatter', 'scattergl', 'histogram'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. technically other types too though, right? I think that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I remember not liking the look of box or bar - it was very squashed up, but perhaps it was the dataset |
||
|
||
CUSTOM_LABEL_ERROR = ( | ||
"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, | |
def _facet_grid_color_categorical(df, x, y, facet_row, facet_col, color_name, | ||
colormap, num_of_rows, | ||
num_of_cols, facet_row_labels, | ||
facet_col_labels, trace_type, | ||
facet_col_labels, temp_trace, | ||
flipped_rows, flipped_cols, show_boxes, | ||
marker_color, kwargs_trace, kwargs_marker): | ||
|
||
|
@@ -193,7 +194,7 @@ def _facet_grid_color_categorical(df, x, y, facet_row, facet_col, color_name, | |
x=group[1][x], | ||
y=group[1][y], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm having a hard time understanding what happens when the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or is just the other variable ignored? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, or the user just doesn't supply the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You found an oversight in my design. Originally this was meant for just scatter, so I was forcing |
||
mode='markers', | ||
type=trace_type, | ||
type=temp_trace, | ||
name=group[0], | ||
marker=dict( | ||
color=colormap[group[0]], | ||
|
@@ -214,7 +215,7 @@ def _facet_grid_color_categorical(df, x, y, facet_row, facet_col, color_name, | |
x=data_by_color[x], | ||
y=data_by_color[y], | ||
mode='markers', | ||
type=trace_type, | ||
type=temp_trace, | ||
name=color_val, | ||
marker=dict( | ||
color=colormap[color_val], | ||
|
@@ -265,7 +266,7 @@ def _facet_grid_color_categorical(df, x, y, facet_row, facet_col, color_name, | |
x=group_filtered[x], | ||
y=group_filtered[y], | ||
mode='markers', | ||
type=trace_type, | ||
type=temp_trace, | ||
name=color_val, | ||
marker=dict( | ||
color=colormap[color_val], | ||
|
@@ -278,7 +279,7 @@ def _facet_grid_color_categorical(df, x, y, facet_row, facet_col, color_name, | |
x=group[x], | ||
y=group[y], | ||
mode='markers', | ||
type=trace_type, | ||
type=temp_trace, | ||
name=color_val, | ||
marker=dict( | ||
color=colormap[color_val], | ||
|
@@ -311,7 +312,7 @@ def _facet_grid_color_categorical(df, x, y, facet_row, facet_col, color_name, | |
def _facet_grid_color_numerical(df, x, y, facet_row, facet_col, color_name, | ||
colormap, num_of_rows, | ||
num_of_cols, facet_row_labels, | ||
facet_col_labels, trace_type, | ||
facet_col_labels, temp_trace, | ||
flipped_rows, flipped_cols, show_boxes, | ||
marker_color, kwargs_trace, kwargs_marker): | ||
|
||
|
@@ -326,7 +327,7 @@ def _facet_grid_color_numerical(df, x, y, facet_row, facet_col, color_name, | |
x=df[x], | ||
y=df[y], | ||
mode='markers', | ||
type=trace_type, | ||
type=temp_trace, | ||
marker=dict( | ||
color=df[color_name], | ||
colorscale=colormap, | ||
|
@@ -346,7 +347,7 @@ def _facet_grid_color_numerical(df, x, y, facet_row, facet_col, color_name, | |
x=group[1][x], | ||
y=group[1][y], | ||
mode='markers', | ||
type=trace_type, | ||
type=temp_trace, | ||
marker=dict( | ||
color=df[color_name], | ||
colorscale=colormap, | ||
|
@@ -396,7 +397,7 @@ def _facet_grid_color_numerical(df, x, y, facet_row, facet_col, color_name, | |
x=group[x], | ||
y=group[y], | ||
mode='markers', | ||
type=trace_type, | ||
type=temp_trace, | ||
marker=dict( | ||
color=df[color_name], | ||
colorscale=colormap, | ||
|
@@ -411,7 +412,7 @@ def _facet_grid_color_numerical(df, x, y, facet_row, facet_col, color_name, | |
x=group[x], | ||
y=group[y], | ||
mode='markers', | ||
type=trace_type, | ||
type=temp_trace, | ||
showlegend=False, | ||
**kwargs | ||
) | ||
|
@@ -439,7 +440,7 @@ def _facet_grid_color_numerical(df, x, y, facet_row, facet_col, color_name, | |
|
||
def _facet_grid(df, x, y, facet_row, facet_col, num_of_rows, | ||
num_of_cols, facet_row_labels, facet_col_labels, | ||
trace_type, flipped_rows, flipped_cols, show_boxes, | ||
temp_trace, flipped_rows, flipped_cols, show_boxes, | ||
marker_color, kwargs_trace, kwargs_marker): | ||
|
||
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, | |
x=df[x], | ||
y=df[y], | ||
mode='markers', | ||
type=trace_type, | ||
type=temp_trace, | ||
marker=dict( | ||
color=marker_color, | ||
**kwargs_marker | ||
|
@@ -470,7 +471,7 @@ def _facet_grid(df, x, y, facet_row, facet_col, num_of_rows, | |
x=group[1][x], | ||
y=group[1][y], | ||
mode='markers', | ||
type=trace_type, | ||
type=temp_trace, | ||
marker=dict( | ||
color=marker_color, | ||
**kwargs_marker | ||
|
@@ -514,7 +515,7 @@ def _facet_grid(df, x, y, facet_row, facet_col, num_of_rows, | |
x=group[x], | ||
y=group[y], | ||
mode='markers', | ||
type=trace_type, | ||
type=temp_trace, | ||
marker=dict( | ||
color=marker_color, | ||
**kwargs_marker | ||
|
@@ -581,7 +582,7 @@ def create_facet_grid(df, x, y, facet_row=None, facet_col=None, | |
:param (int) height: the height of the facet grid figure. | ||
:param (int) width: the width of the facet grid figure. | ||
:param (str) trace_type: decides the type of plot to appear in the | ||
facet grid. The options are 'scatter' and 'scattergl'. | ||
facet grid. The options are 'scatter', 'scattergl' and 'histogram'. | ||
Default = 'scatter'. | ||
:param (str) scales: determines if axes have fixed ranges or not. Valid | ||
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, | |
"'scales' must be set to 'fixed', 'free_x', 'free_y' and 'free'." | ||
) | ||
|
||
if trace_type not in ['scatter', 'scattergl']: | ||
if trace_type not in VALID_TRACE_TYPES: | ||
raise exceptions.PlotlyError( | ||
"'trace_type' must be 'scatter' or 'scattergl'." | ||
"'trace_type' must be in {}".format(VALID_TRACE_TYPES) | ||
) | ||
|
||
temp_trace = 'scatter' if (trace_type == 'histogram') else trace_type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since this renders the trace as scatter first, the histogram attributes can't be passed. For example:
|
||
|
||
# seperate kwargs for marker and else | ||
if 'marker' in kwargs: | ||
kwargs_marker = kwargs['marker'] | ||
|
@@ -808,7 +811,7 @@ def create_facet_grid(df, x, y, facet_row=None, facet_col=None, | |
fig = _facet_grid_color_categorical( | ||
df, x, y, facet_row, facet_col, color_name, colormap, | ||
num_of_rows, num_of_cols, facet_row_labels, facet_col_labels, | ||
trace_type, flipped_rows, flipped_cols, show_boxes, | ||
temp_trace, flipped_rows, flipped_cols, show_boxes, | ||
marker_color, kwargs_trace, kwargs_marker | ||
) | ||
|
||
|
@@ -827,7 +830,7 @@ def create_facet_grid(df, x, y, facet_row=None, facet_col=None, | |
fig = _facet_grid_color_categorical( | ||
df, x, y, facet_row, facet_col, color_name, colormap, | ||
num_of_rows, num_of_cols, facet_row_labels, | ||
facet_col_labels, trace_type, flipped_rows, | ||
facet_col_labels, temp_trace, flipped_rows, | ||
flipped_cols, show_boxes, marker_color, kwargs_trace, | ||
kwargs_marker | ||
) | ||
|
@@ -839,7 +842,7 @@ def create_facet_grid(df, x, y, facet_row=None, facet_col=None, | |
fig = _facet_grid_color_numerical( | ||
df, x, y, facet_row, facet_col, color_name, | ||
colorscale_list, num_of_rows, num_of_cols, | ||
facet_row_labels, facet_col_labels, trace_type, | ||
facet_row_labels, facet_col_labels, temp_trace, | ||
flipped_rows, flipped_cols, show_boxes, marker_color, | ||
kwargs_trace, kwargs_marker | ||
) | ||
|
@@ -855,7 +858,7 @@ def create_facet_grid(df, x, y, facet_row=None, facet_col=None, | |
fig = _facet_grid_color_numerical( | ||
df, x, y, facet_row, facet_col, color_name, | ||
colorscale_list, num_of_rows, num_of_cols, | ||
facet_row_labels, facet_col_labels, trace_type, | ||
facet_row_labels, facet_col_labels, temp_trace, | ||
flipped_rows, flipped_cols, show_boxes, marker_color, | ||
kwargs_trace, kwargs_marker | ||
) | ||
|
@@ -864,15 +867,15 @@ def create_facet_grid(df, x, y, facet_row=None, facet_col=None, | |
fig = _facet_grid_color_numerical( | ||
df, x, y, facet_row, facet_col, color_name, | ||
colorscale_list, num_of_rows, num_of_cols, | ||
facet_row_labels, facet_col_labels, trace_type, | ||
facet_row_labels, facet_col_labels, temp_trace, | ||
flipped_rows, flipped_cols, show_boxes, marker_color, | ||
kwargs_trace, kwargs_marker | ||
) | ||
|
||
else: | ||
fig = _facet_grid( | ||
df, x, y, facet_row, facet_col, num_of_rows, num_of_cols, | ||
facet_row_labels, facet_col_labels, trace_type, flipped_rows, | ||
facet_row_labels, facet_col_labels, temp_trace, flipped_rows, | ||
flipped_cols, show_boxes, marker_color, kwargs_trace, | ||
kwargs_marker | ||
) | ||
|
@@ -1012,4 +1015,10 @@ def create_facet_grid(df, x, y, facet_row=None, facet_col=None, | |
if '{}axis'.format(x_y) in key and range_are_numbers: | ||
fig['layout'][key]['range'] = [min_range, max_range] | ||
|
||
if trace_type == 'histogram': | ||
for trace in fig['data']: | ||
trace['type'] = trace_type | ||
del trace['marker']['size'] | ||
del trace['mode'] | ||
|
||
return fig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe
figure_factory.create_facet_grid
just to be super clear