Skip to content
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

ENH: Dictionary based hatch for df.plot #46965

Open
Wheest opened this issue May 7, 2022 · 1 comment
Open

ENH: Dictionary based hatch for df.plot #46965

Wheest opened this issue May 7, 2022 · 1 comment
Labels
Enhancement Needs Triage Issue that has not been reviewed by a pandas team member Visualization plotting

Comments

@Wheest
Copy link

Wheest commented May 7, 2022

Is your feature request related to a problem?

When using df.plot, we can set the colors of bars using a dictionary, e.g.:

df = pd.DataFrame(np.random.rand(10, 4), columns=["a", "b", "c", "d"])

colors = {"a": "red", "b": "blue", "c": "green", "d": "red"}
df.plot(kind="bar", color=colors, hatch="/");

image

However, we cannot do the same with hatches. This can only be set on a global level as far as I can tell.

Describe the solution you'd like

DataFrame.plot() should be able to take a dictionary of hatches, and set them in the same way as color.

E.g.,

df = pd.DataFrame(np.random.rand(10, 4), columns=["a", "b", "c", "d"])

colors = {"a": "red", "b": "blue", "c": "green", "d": "red"}
hatches = {"a": "/", "b": "o", "c": "", "d": "x"}

df.plot(kind="bar", color=colors, hatch=hatches);

Describe alternatives you've considered

There are StackOverflow discussions of this feature, where users have suggested hacks and workarounds to this, using native matplotlib.

E.g. this answer

bars = ax.patches
patterns =('-', '+', 'x','/','//','O','o','\\','\\\\')
hatches = [p for p in patterns for i in range(len(df))]
for bar, hatch in zip(bars, hatches):
    bar.set_hatch(hatch)

However, having it integrated in pandas, with the advantages of using a dictionary of column names would be preferable.

@Wheest Wheest added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels May 7, 2022
@brurosa
Copy link

brurosa commented Oct 20, 2022

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Needs Triage Issue that has not been reviewed by a pandas team member Visualization plotting
Projects
None yet
Development

No branches or pull requests

3 participants