Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[MNT]: Refactor grouped_bar orientation logic using shared common_kwargs #30729

Closed
@ilakkmanoharan

Description

@ilakkmanoharan

Summary

In the Axes.grouped_bar() implementation, the code currently passes repetitive keyword arguments separately for vertical and horizontal orientations.

Tim Hoffmann suggested a more maintainable approach by introducing a shared common_kwargs dictionary to consolidate repeated parameters such as align, label, color, and hatch.

Current Code Snippet::

if orientation == "vertical":    bc = self.bar(lefts, hs, width=bar_width, align="edge",                  label=label, color=color, hatch=hatch_pattern, **kwargs)else:    bc = self.barh(lefts, hs, height=bar_width, align="edge",                   label=label, color=color, hatch=hatch_pattern, **kwargs)

Proposed Refactor::

common_kwargs = dict(align="edge", label=label, color=color, hatch=hatch_pattern)if orientation == "vertical":    bc = self.bar(lefts, hs, width=bar_width, **common_kwargs, **kwargs)else:    bc = self.barh(lefts, hs, height=bar_width, **common_kwargs, **kwargs)

Benefits
Eliminates redundant code across orientation branches.
Reduces likelihood of introducing inconsistencies or errors during future updates.
Makes the code cleaner and easier to maintain.
Removes the need for a separate orientation-specific test since the logic path becomes symmetrical.

Reference:
Suggestion from@timhoffm in PR ENH: Add broadcasted hatch to grouped_bar#30683

Proposed fix

common_kwargs = dict(align="edge", label=label, color=color, hatch=hatch_pattern)if orientation == "vertical":    bc = self.bar(lefts, hs, width=bar_width, **common_kwargs, **kwargs)else:    bc = self.barh(lefts, hs, height=bar_width, **common_kwargs, **kwargs)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp