Skip to content

_dataframe.boxplot_ with _where_ and _by_ does not respect color keyword #26214

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
bnlawrence opened this issue Apr 26, 2019 · 1 comment · Fixed by #26456
Closed

_dataframe.boxplot_ with _where_ and _by_ does not respect color keyword #26214

bnlawrence opened this issue Apr 26, 2019 · 1 comment · Fixed by #26456
Labels

Comments

@bnlawrence
Copy link

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
@bnlawrence
Copy link
Author

Sorry about the title, and not noticing the mistake in the matplotlib backend version: 3.0.2

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.

2 participants