Skip to content

df.plot.bar not showing colors as expected as compared to matplotlib #17240

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
rajgupt opened this issue Aug 13, 2017 · 2 comments
Closed

df.plot.bar not showing colors as expected as compared to matplotlib #17240

rajgupt opened this issue Aug 13, 2017 · 2 comments
Labels
Duplicate Report Duplicate issue or pull request Visualization plotting

Comments

@rajgupt
Copy link

rajgupt commented Aug 13, 2017

def bar(self, x=None, y=None, **kwds):
"""
Vertical bar plot
.. versionadded:: 0.17.0
Parameters
----------
x, y : label or position, optional
Coordinates for each point.
**kwds : optional
Keyword arguments to pass on to :py:meth:`pandas.DataFrame.plot`.
Returns
-------
axes : matplotlib.AxesSubplot or np.array of them
"""
return self(kind='bar', x=x, y=y, **kwds)

import pandas as pd
import numpy as np
import matplotlib
get_ipython().magic(u'pylab inline')

# In[17]:
df = pd.DataFrame({'id': range(1,11), 'normcolor': np.random.rand(10), 'count': np.random.randint(0,100,(10))})

# In[21]:
colors = matplotlib.cm.hsv(df['normcolor'])
df.plot.bar('id','count', color=colors) # return plot with not color variation


# In[22]:
plt.bar(df['id'], df['count'], color=colors) # returns plot as expected

Current Output

image

Correct Output

image

@rajgupt
Copy link
Author

rajgupt commented Aug 13, 2017

import pandas as pd
pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 2.7.12.final.0
python-bits: 32
OS: Windows
OS-release: 10
machine: x86
processor: x86 Family 6 Model 58 Stepping 9, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.20.3
pytest: 2.8.5
pip: 9.0.1
setuptools: 23.0.0
Cython: 0.23.4
numpy: 1.13.1
scipy: 0.19.1
xarray: None
IPython: 4.2.0
sphinx: 1.3.5
patsy: 0.4.0
dateutil: 2.4.2
pytz: 2015.7
blosc: None
bottleneck: 1.0.0
tables: 3.2.2
numexpr: 2.6.2
feather: None
matplotlib: 1.5.1
openpyxl: 2.3.2
xlrd: 0.9.4
xlwt: 1.0.0
xlsxwriter: 0.8.4
lxml: 3.5.0
bs4: 4.4.1
html5lib: None
sqlalchemy: 1.0.11
pymysql: None
psycopg2: None
jinja2: 2.8
s3fs: None
pandas_gbq: None
pandas_datareader: None
None

@chris-b1
Copy link
Contributor

duplicate of #16822, PR to fix welcome! From that issue, df.plot.bar('id','count', color=[colors]) is apparently a workaround.

@chris-b1 chris-b1 added Duplicate Report Duplicate issue or pull request Visualization plotting labels Aug 13, 2017
@chris-b1 chris-b1 added this to the No action milestone Aug 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request Visualization plotting
Projects
None yet
Development

No branches or pull requests

2 participants