@@ -652,9 +652,6 @@ def set_cartesian_axis_opts(args, axis, letter, orders):
652
652
653
653
654
654
def configure_cartesian_marginal_axes (args , fig , orders ):
655
- if "histogram" in [args ["marginal_x" ], args ["marginal_y" ]]:
656
- fig .layout ["barmode" ] = "overlay"
657
-
658
655
nrows = len (fig ._grid_ref )
659
656
ncols = len (fig ._grid_ref [0 ])
660
657
@@ -1489,25 +1486,21 @@ def build_dataframe(args, constructor):
1489
1486
# PySpark to pandas.
1490
1487
is_pd_like = False
1491
1488
1492
- # Flag that indicates if data_frame requires to be converted to arrow via the
1493
- # dataframe interchange protocol.
1494
- # True if Ibis, DuckDB, Vaex or implements __dataframe__
1489
+ # Flag that indicates if data_frame needs to be converted to PyArrow.
1490
+ # True if Ibis, DuckDB, Vaex, or implements __dataframe__
1495
1491
needs_interchanging = False
1496
1492
1497
1493
# If data_frame is provided, we parse it into a narwhals DataFrame, while accounting
1498
1494
# for compatibility with pandas specific paths (e.g. Index/MultiIndex case).
1499
1495
if df_provided :
1500
-
1501
1496
# data_frame is pandas-like DataFrame (pandas, modin.pandas, cudf)
1502
1497
if nw .dependencies .is_pandas_like_dataframe (args ["data_frame" ]):
1503
-
1504
1498
columns = args ["data_frame" ].columns # This can be multi index
1505
1499
args ["data_frame" ] = nw .from_native (args ["data_frame" ], eager_only = True )
1506
1500
is_pd_like = True
1507
1501
1508
1502
# data_frame is pandas-like Series (pandas, modin.pandas, cudf)
1509
1503
elif nw .dependencies .is_pandas_like_series (args ["data_frame" ]):
1510
-
1511
1504
args ["data_frame" ] = nw .from_native (
1512
1505
args ["data_frame" ], series_only = True
1513
1506
).to_frame ()
@@ -1861,7 +1854,6 @@ def _check_dataframe_all_leaves(df: nw.DataFrame) -> None:
1861
1854
for row_idx , row in zip (
1862
1855
null_indices_mask , null_mask .filter (null_indices_mask ).iter_rows ()
1863
1856
):
1864
-
1865
1857
i = row .index (True )
1866
1858
1867
1859
if not all (row [i :]):
@@ -1990,7 +1982,6 @@ def process_dataframe_hierarchy(args):
1990
1982
1991
1983
if args ["color" ]:
1992
1984
if discrete_color :
1993
-
1994
1985
discrete_aggs .append (args ["color" ])
1995
1986
agg_f [args ["color" ]] = nw .col (args ["color" ]).max ()
1996
1987
agg_f [f'{ args ["color" ]} { n_unique_token } ' ] = (
@@ -2045,7 +2036,6 @@ def post_agg(dframe: nw.LazyFrame, continuous_aggs, discrete_aggs) -> nw.LazyFra
2045
2036
).drop ([f"{ col } { n_unique_token } " for col in discrete_aggs ])
2046
2037
2047
2038
for i , level in enumerate (path ):
2048
-
2049
2039
dfg = (
2050
2040
df .group_by (path [i :], drop_null_keys = True )
2051
2041
.agg (** agg_f )
@@ -2487,6 +2477,10 @@ def make_figure(args, constructor, trace_patch=None, layout_patch=None):
2487
2477
constructor = go .Bar
2488
2478
args = process_dataframe_timeline (args )
2489
2479
2480
+ # If we have marginal histograms, set barmode to "overlay"
2481
+ if "histogram" in [args .get ("marginal_x" ), args .get ("marginal_y" )]:
2482
+ layout_patch ["barmode" ] = "overlay"
2483
+
2490
2484
trace_specs , grouped_mappings , sizeref , show_colorbar = infer_config (
2491
2485
args , constructor , trace_patch , layout_patch
2492
2486
)
@@ -2558,7 +2552,12 @@ def make_figure(args, constructor, trace_patch=None, layout_patch=None):
2558
2552
legendgroup = trace_name ,
2559
2553
showlegend = (trace_name != "" and trace_name not in trace_names ),
2560
2554
)
2561
- if trace_spec .constructor in [go .Bar , go .Violin , go .Box , go .Histogram ]:
2555
+
2556
+ # Set 'offsetgroup' only in group barmode (or if no barmode is set)
2557
+ barmode = layout_patch .get ("barmode" )
2558
+ if trace_spec .constructor in [go .Bar , go .Box , go .Violin , go .Histogram ] and (
2559
+ barmode == "group" or barmode is None
2560
+ ):
2562
2561
trace .update (alignmentgroup = True , offsetgroup = trace_name )
2563
2562
trace_names .add (trace_name )
2564
2563
0 commit comments