Skip to content

plot.bar misalignment when width=1 #12979

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

Closed
kdebrab opened this issue Apr 25, 2016 · 3 comments
Closed

plot.bar misalignment when width=1 #12979

kdebrab opened this issue Apr 25, 2016 · 3 comments
Labels
Milestone

Comments

@kdebrab
Copy link
Contributor

kdebrab commented Apr 25, 2016

Two minor issues with the width optional argument of plot.bar() in Pandas 0.18.0:

  1. Using width=1 (integer) causes misalignment of the x-axis
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.random((6, 5)) * 10, index=list('abcdef'), columns=list('ABCDE'))
df.plot.bar(stacked=True, width=1)

figure_1

Compare this with the correct behaviour when defining width as a float:

df.plot.bar(stacked=True, width=1.)

figure_2

  1. Using width=None causes a TypeError, where I would expect the default behaviour.
@TomAugspurger
Copy link
Contributor

For the first one, I don't see a problem:

gh

Could you post the output of pd.show_versions() along with your OS information?

For the default, it's 0.5 but we haven't finished documenting all the keyword arguments after the .plot namespace was added in 0.17.

@kdebrab
Copy link
Contributor Author

kdebrab commented Apr 25, 2016

As requested, output of pd.show_versions():

INSTALLED VERSIONS

commit: None
python: 2.7.10.final.0
python-bits: 32
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 42 Stepping 7, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.18.0
nose: 1.3.7
pip: 8.1.1
setuptools: 20.3.1
Cython: 0.20
numpy: 1.10.4
scipy: 0.16.0b2
statsmodels: 0.6.1
xarray: None
IPython: 4.1.2
sphinx: 1.3.6
patsy: 0.3.0
dateutil: 2.5.1
pytz: 2016.2
blosc: None
bottleneck: 0.8.0
tables: None
numexpr: None
matplotlib: 1.5.1
openpyxl: 1.6.2
xlrd: 0.9.2
xlwt: 0.7.5
xlsxwriter: None
lxml: None
bs4: 4.3.2
html5lib: 0.999999
httplib2: 0.9.1
apiclient: None
sqlalchemy: 0.7.9
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None

Seeing the style of your figure, I'd guess you're using matplotlib 2.x (development)? Thus, it seems the first issue originates in matplotlib and is fixed in the development version of matplotlib, but not in the latest stable matplotlib version 1.5.1?

With regard to the second issue, I knew the default is 0.5. It is just a matter of usability/consistency. Most optional arguments use the default value (i.c. 0.5) when one explicitly sets them to None. Apparently this isn't the case for the 'width' argument. Not very important of course, but I just thought of mentioning this.

The fix/workaround is rather trivial. Adding the line width = float(width or 0.5) fixes both issues for me.

@sinhrks
Copy link
Member

sinhrks commented Apr 25, 2016

As you use python2, looks to be caused by somewhere uses division by integer. PR is appreciated:)

@sinhrks sinhrks added Bug and removed Can't Repro labels Apr 29, 2016
@jreback jreback added this to the 0.18.1 milestone Apr 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants