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

Barplot - cannot override width #2508

Closed
rupertcw opened this issue Mar 15, 2021 · 4 comments · Fixed by #2860
Closed

Barplot - cannot override width #2508

rupertcw opened this issue Mar 15, 2021 · 4 comments · Fixed by #2860

Comments

@rupertcw
Copy link

rupertcw commented Mar 15, 2021

Version:
0.11.1

OS:
Ubuntu

Description:
When calling barplot(..., width=width) a TypeError is raised from matplotlib:
TypeError: bar() got multiple values for argument 'width'

I think barplot() should either:

  • raise before reaching matplotlib explaining why width cannot be overridden if there's a good reason
  • allow overriding and pass the new value to matplotlib

This goes for the other kwargs accepted by matplotlib as well, of course.

@mwaskom
Copy link
Owner

mwaskom commented Mar 15, 2021

I think this will get implemented when it's barplot's time in the #2429 barrel.

BTW it has been my experience that most of the time people ask about setting the barplot width, they are trying to use hue in a situation where x and hue are crossed (rather than nested) and would benefit from knowing about dodge=False.

@rupertcw
Copy link
Author

Great - looking forward to it.

My use-case is the following:
I have a Pandas DataFrame with a DatetimeIndex and a column with some integers.
I want to plot the index on the X-axis and the integers on the Y-axis - sample of my code below:
sns.barplot(x=data.index, y="my_int_column", data=data, color="blue")

The issue is that because I'm potentially showing a timeseries of up to 2 years, at a weekly granularity, the X labels overlap each other and are illegible, so I rotate them.
This still doesn't look great so I was wondering if widening the bars would give the labels extra space at the sides - e.g. via width=.
I modified seaborn to work with the overridden width but then the bars are overlapping in the chart so maybe this is not the way.

@mwaskom
Copy link
Owner

mwaskom commented Mar 16, 2021

No, making the bars wider with the same figure width will not create extra space for the labels.

@b-grimaud
Copy link

Seconding this, barplots with only two or three bars can result in unappealingly large plots. Hue nesting does result in much nicer sizes, but also leads to weird spacing between some bars, even with dodge=True.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants