-
Notifications
You must be signed in to change notification settings - Fork 15
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
fix: Make dx
histogram behavior consistent with px
#1002
base: main
Are you sure you want to change the base?
Changes from all commits
75eed23
e1e5a59
f495a10
07588a5
c50d052
1f8e9ae
ae85f06
cdbed39
d0110e7
1034629
fdf86e7
cb7f42f
4c7dca7
42a346a
ba4ccc0
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 |
---|---|---|
|
@@ -111,7 +111,8 @@ | |
"current_col", | ||
"current_var", | ||
"labels", | ||
"hist_val_name", | ||
"hist_agg_label_h", | ||
"hist_agg_label_v", | ||
"pivot_vars", | ||
"current_partition", | ||
"colors", | ||
|
@@ -824,7 +825,8 @@ def hover_text_generator( | |
|
||
def compute_labels( | ||
hover_mapping: list[dict[str, str]], | ||
hist_val_name: str | None, | ||
hist_agg_label_h: str | None, | ||
hist_agg_label_v: str | None, | ||
heatmap_agg_label: str | None, | ||
# hover_data - todo, dependent on arrays supported in data mappings | ||
types: set[str], | ||
|
@@ -837,7 +839,8 @@ def compute_labels( | |
|
||
Args: | ||
hover_mapping: The mapping of variables to columns | ||
hist_val_name: The histogram name for the value axis, generally histfunc | ||
hist_agg_label_h: The histogram agg label when oriented horizontally | ||
hist_agg_label_v: The histogram agg label when oriented vertically | ||
heatmap_agg_label: The aggregate density heatmap column title | ||
types: Any types of this chart that require special processing | ||
labels: A dictionary of old column name to new column name mappings | ||
|
@@ -847,7 +850,7 @@ def compute_labels( | |
the renamed current_col | ||
""" | ||
|
||
calculate_hist_labels(hist_val_name, hover_mapping[0]) | ||
calculate_hist_labels(hist_agg_label_h, hist_agg_label_v, hover_mapping[0]) | ||
|
||
calculate_density_heatmap_labels(heatmap_agg_label, hover_mapping[0], labels) | ||
|
||
|
@@ -880,27 +883,31 @@ def calculate_density_heatmap_labels( | |
|
||
|
||
def calculate_hist_labels( | ||
hist_val_name: str | None, current_mapping: dict[str, str] | ||
hist_agg_label_h: str | None, | ||
hist_agg_label_v: str | None, | ||
hover_mapping: dict[str, str], | ||
) -> None: | ||
"""Calculate the histogram labels | ||
|
||
Args: | ||
hist_val_name: The histogram name for the value axis, generally histfunc | ||
current_mapping: The mapping of variables to columns | ||
hist_agg_label_h: The histogram agg label when oriented horizontally | ||
hist_agg_label_v: The histogram agg label when oriented vertically | ||
hover_mapping: The mapping of variables to columns | ||
|
||
""" | ||
if hist_val_name: | ||
# swap the names | ||
current_mapping["x"], current_mapping["y"] = ( | ||
current_mapping["y"], | ||
current_mapping["x"], | ||
) | ||
# only one should be set | ||
if hist_agg_label_h: | ||
Comment on lines
+898
to
+899
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. Might be a bit clearer to make the args |
||
# a bar chart oriented horizontally has the histfunc on the x-axis | ||
hover_mapping["x"] = hist_agg_label_h | ||
elif hist_agg_label_v: | ||
hover_mapping["y"] = hist_agg_label_v | ||
|
||
|
||
def add_axis_titles( | ||
custom_call_args: dict[str, Any], | ||
hover_mapping: list[dict[str, str]], | ||
hist_val_name: str | None, | ||
hist_agg_label_h: str | None, | ||
hist_agg_label_v: str | None, | ||
heatmap_agg_label: str | None, | ||
) -> None: | ||
"""Add axis titles. Generally, this only applies when there is a list variable | ||
|
@@ -909,7 +916,8 @@ def add_axis_titles( | |
custom_call_args: The custom_call_args that are used to | ||
create hover and axis titles | ||
hover_mapping: The mapping of variables to columns | ||
hist_val_name: The histogram name for the value axis, generally histfunc | ||
hist_agg_label_h: The histogram agg label when oriented horizontally | ||
hist_agg_label_v: The histogram agg label when oriented vertically | ||
heatmap_agg_label: The aggregate density heatmap column title | ||
|
||
""" | ||
|
@@ -919,8 +927,8 @@ def add_axis_titles( | |
new_xaxis_titles = None | ||
new_yaxis_titles = None | ||
|
||
if hist_val_name: | ||
# hist names are already set up in the mapping | ||
if hist_agg_label_h or hist_agg_label_v: | ||
# hist labels are already set up in the mapping | ||
new_xaxis_titles = [hover_mapping[0].get("x", None)] | ||
new_yaxis_titles = [hover_mapping[0].get("y", None)] | ||
|
||
|
@@ -978,14 +986,16 @@ def create_hover_and_axis_titles( | |
types = get_list_var_info(data_cols) | ||
|
||
labels = custom_call_args.get("labels", None) | ||
hist_val_name = custom_call_args.get("hist_val_name", None) | ||
hist_agg_label_h = custom_call_args.get("hist_agg_label_h", None) | ||
hist_agg_label_v = custom_call_args.get("hist_agg_label_v", None) | ||
heatmap_agg_label = custom_call_args.get("heatmap_agg_label", None) | ||
|
||
current_partition = custom_call_args.get("current_partition", {}) | ||
|
||
compute_labels( | ||
hover_mapping, | ||
hist_val_name, | ||
hist_agg_label_h, | ||
hist_agg_label_v, | ||
heatmap_agg_label, | ||
types, | ||
labels, | ||
|
@@ -998,7 +1008,13 @@ def create_hover_and_axis_titles( | |
# it's possible that heatmap_agg_label was relabeled, so grab the new label | ||
heatmap_agg_label = hover_mapping[0]["z"] | ||
|
||
add_axis_titles(custom_call_args, hover_mapping, hist_val_name, heatmap_agg_label) | ||
add_axis_titles( | ||
custom_call_args, | ||
hover_mapping, | ||
hist_agg_label_h, | ||
hist_agg_label_v, | ||
heatmap_agg_label, | ||
) | ||
|
||
return hover_text | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
HISTOGRAM_DEFAULTS, | ||
default_callback, | ||
) | ||
from ..types import PartitionableTableLike | ||
from ..types import PartitionableTableLike, Orientation | ||
|
||
|
||
def violin( | ||
|
@@ -321,6 +321,7 @@ def histogram( | |
pattern_shape_map: dict[str | tuple[str], str] | None = None, | ||
marginal: str | None = None, | ||
opacity: float | None = None, | ||
orientation: Orientation | None = None, | ||
barmode: str = HISTOGRAM_DEFAULTS["barmode"], | ||
barnorm: str = HISTOGRAM_DEFAULTS["barnorm"], | ||
histnorm: str = HISTOGRAM_DEFAULTS["histnorm"], | ||
|
@@ -342,11 +343,11 @@ def histogram( | |
Args: | ||
table: A table to pull data from. | ||
x: A column name or list of columns that contain x-axis values. | ||
Only one of x or y can be specified. If x is specified, | ||
the bars are drawn horizontally. | ||
Column values must be numeric. If x is specified, | ||
the bars are drawn vertically by default. | ||
y: A column name or list of columns that contain y-axis values. | ||
Only one of x or y can be specified. If y is specified, the | ||
bars are drawn vertically. | ||
Column values must be numeric. If only y is specified, | ||
the bars are drawn horizontally by default. | ||
Comment on lines
+346
to
+350
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. Just making sure this has different behavior from bar in that the columns must be numeric. From the bar orientation docstring it looks like 1 value can be non-numeric |
||
by: A column or list of columns that contain values to plot the figure traces by. | ||
All values or combination of values map to a unique design. The variable | ||
by_vars specifies which design elements are used. | ||
|
@@ -375,6 +376,11 @@ def histogram( | |
marginal: The type of marginal; histogram, violin, rug, box | ||
opacity: Opacity to apply to all markers. 0 is completely transparent | ||
and 1 is completely opaque. | ||
orientation: The orientation of the bars. | ||
If 'v', the bars are vertical. | ||
If 'h', the bars are horizontal. | ||
Defaults to 'v' if `x` is specified. | ||
Defaults to 'h' if only `y` is specified. | ||
barmode: If 'relative', bars are stacked. If | ||
'overlay', bars are drawn on top of each other. If 'group', bars are | ||
drawn next to each other. | ||
|
@@ -396,6 +402,7 @@ def histogram( | |
histfunc: The function to use when aggregating within bins. One of | ||
'abs_sum', 'avg', 'count', 'count_distinct', 'max', 'median', 'min', 'std', | ||
'sum', or 'var' | ||
Defaults to 'count' if only one of x or y is specified and 'sum' if both are. | ||
cumulative: If True, values are cumulative. | ||
nbins: The number of bins to use. | ||
text_auto: If True, display the value at each bar. | ||
|
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.
I would mention something like "If the plot orientation is vertical, the
x
column will be binned and they
column aggregated. The operations are flipped if the plot orientation is horizontal."I don't know which orientation corresponds with which pairing