dataframe.boxplot with where and by does not respect color keyword · Issue #26214 · pandas-dev/pandas (original) (raw)
Bug report
Bug summary
The boxplot method on a dataframe which is using the "column, by" keywords does
not respect the color keyword, and in fact crashes if it is present. This is not consistent with the documentation here.
Code for reproduction
import pandas as pd import matplotlib.pyplot as plt import numpy as np
def make_dummy_data(): """ Return """ df1 = pd.DataFrame(np.random.rand(10, 3), columns = ['x', 'y', 'z']) df2 = pd.DataFrame(2*np.random.rand(10, 3), columns = ['x', 'y', 'z']) return df1, df2
def comparative_results(): """ stuff """
df1, df2 = make_dummy_data()
def draw_plot(ax, data, edge_color, fill_color=None):
""" Controls details of color"""
colors = dict(boxes=edge_color, whiskers=edge_color, medians=edge_color, caps=edge_color)
ax = data.boxplot(column=['x'], by=['z'], showfliers=False, ax=ax, color=colors)
return ax
ax = None
ax = draw_plot(ax, df1, 'k')
ax = draw_plot(ax, df2, 'r')
ax.set_title('dummy to expose bug')
plt.show()
if name == "main": comparative_results()
Actual outcome
Traceback (most recent call last):
File "/Users/BNL28/Code/DataPerformance/bug_report.py", line 33, in <module>
comparative_results()
File "/Users/BNL28/Code/DataPerformance/bug_report.py", line 26, in comparative_results
ax = draw_plot(ax, df1, 'k')
File "/Users/BNL28/Code/DataPerformance/bug_report.py", line 22, in draw_plot
ax = data.boxplot(column=['x'], by=['z'], showfliers=False, ax=ax, color=colors)
File "/Users/BNL28/anaconda3/lib/python3.6/site-packages/pandas/plotting/_core.py", line 2254, in boxplot_frame
return_type=return_type, **kwds)
File "/Users/BNL28/anaconda3/lib/python3.6/site-packages/pandas/plotting/_core.py", line 2223, in boxplot
return_type=return_type)
File "/Users/BNL28/anaconda3/lib/python3.6/site-packages/pandas/plotting/_core.py", line 2683, in _grouped_plot_by_column
re_plotf = plotf(keys, values, ax, **kwargs)
File "/Users/BNL28/anaconda3/lib/python3.6/site-packages/pandas/plotting/_core.py", line 2191, in plot_group
bp = ax.boxplot(values, **kwds)
File "/Users/BNL28/anaconda3/lib/python3.6/site-packages/matplotlib/__init__.py", line 1810, in inner
return func(ax, *args, **kwargs)
TypeError: boxplot() got an unexpected keyword argument 'color'
Process finished with exit code 1
Expected outcome
Expect two sets of box plots, one coloured black, and one coloured red. Code runs ok with no color keyword, but the boxes are indistinguishable without colour control.
Environment
- Operating system: OSX
- Matplotlib version: 3.0.2
- Matplotlib backend (
print(matplotlib.get_backend())
): - Python version: Python 3.6.8 |Anaconda, Inc.| (default, Dec 29 2018, 19:04:46)
- Pandas version 0.24.2