MCPcopy
hub / github.com/pandas-dev/pandas / _grouped_plot_by_column

Function _grouped_plot_by_column

pandas/plotting/_matplotlib/boxplot.py:288–343  ·  view source on GitHub ↗
(
    plotf,
    data,
    columns=None,
    by=None,
    numeric_only: bool = True,
    grid: bool = False,
    figsize: tuple[float, float] | None = None,
    ax=None,
    layout=None,
    return_type=None,
    **kwargs,
)

Source from the content-addressed store, hash-verified

286
287
288def _grouped_plot_by_column(
289 plotf,
290 data,
291 columns=None,
292 by=None,
293 numeric_only: bool = True,
294 grid: bool = False,
295 figsize: tuple[float, float] | None = None,
296 ax=None,
297 layout=None,
298 return_type=None,
299 **kwargs,
300):
301 grouped = data.groupby(by, observed=False)
302 if columns is None:
303 if not isinstance(by, (list, tuple)):
304 by = [by]
305 columns = data._get_numeric_data().columns.difference(by)
306 naxes = len(columns)
307 fig, axes = create_subplots(
308 naxes=naxes,
309 sharex=kwargs.pop("sharex", True),
310 sharey=kwargs.pop("sharey", True),
311 figsize=figsize,
312 ax=ax,
313 layout=layout,
314 )
315
316 # GH 45465: move the "by" label based on "vert"
317 xlabel, ylabel = kwargs.pop("xlabel", None), kwargs.pop("ylabel", None)
318 if kwargs.get("vert", True):
319 xlabel = xlabel or by
320 else:
321 ylabel = ylabel or by
322
323 ax_values = []
324
325 for ax, col in zip(flatten_axes(axes), columns, strict=False):
326 gp_col = grouped[col]
327 keys, values = zip(*gp_col, strict=True)
328 re_plotf = plotf(keys, values, ax, xlabel=xlabel, ylabel=ylabel, **kwargs)
329 ax.set_title(col)
330 ax_values.append(re_plotf)
331 ax.grid(grid)
332
333 result = pd.Series(ax_values, index=columns, copy=False)
334
335 # Return axes in multiplot case, maybe revisit later # 985
336 if return_type is None:
337 result = axes
338
339 byline = by[0] if len(by) == 1 else by
340 fig.suptitle(f"Boxplot grouped by {byline}")
341 maybe_adjust_figure(fig, bottom=0.15, top=0.9, left=0.1, right=0.9, wspace=0.2)
342
343 return result
344
345

Callers 1

boxplotFunction · 0.85

Calls 9

create_subplotsFunction · 0.90
flatten_axesFunction · 0.90
maybe_adjust_figureFunction · 0.90
_get_numeric_dataMethod · 0.80
groupbyMethod · 0.45
differenceMethod · 0.45
popMethod · 0.45
getMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected