BUG: Boxplot to return axes, not dict
State: closed

Fixes #4264. 


Labels:
name: Visualization
description: plotting
name: API Design

Comments:
- can you hook up travis
- test
- release notes entry

is this consistent with #4020 (I believe that's the point here!)

@jreback 
- Hooked up Travis
- I don't think there's much testing to add here. I'm not sure we even want to keep the last commit i just pushed. I think it has much larger implications about all of the plotting functions that we really don't want to deal with in the simple PR that deals with just a simple issue
- Release notes coming after we decide on the direction to take re: my last "TST" commit

@cpcloud can u take a look

Looks okay to me, modulo what I said in the outdated diff.

@jreback Do you think it's worth noting in the docs how to recreate the `dict` that's returned as of now? `matplotlib` returns a `dict` as well so users coming from there might expect a `dict`.

@cpcloud 
The more I think about this, the more I think that boxplot should return the `ax` to be consistent with the other functions, but there is value in the `dict` of `Artists` as well. Namely, boxplots of out of the -- uh-- box are pretty ugly. I always keep a function like this handy:

``` python
def formatBoxplot(bp, color='b', marker='o', linestyle='-'):
    # format the box itself
    for box in bp['boxes']:
        plt.setp(box, color='k', linewidth=0.75, zorder=4)

    # format the medians
    for med in bp['medians']:
        plt.setp(med, linewidth=1.00, color=color, linestyle=linestyle, zorder=2)

    # format the whiskers
    for whi in bp['whiskers']:
        plt.setp(whi, linestyle='-', color='k', linewidth=0.75, zorder=4)

    # format the caps on top of the whiskers
    for cap in bp['caps']:
        plt.setp(cap, linewidth=0.75, zorder=4)

    # format the outliers
    for fli in bp['fliers']:
        plt.setp(fli, marker=marker, markersize=4, zorder=4,
                 markerfacecolor='none', markeredgecolor=color)
```

Any thoughts on returning both the `Axes` and the `dict`.

@phobson I was thinking something similar after glancing at the matplotlib source, *sigh*. I'm not sure there's a point to return both the axes and the dict since you can get the axes easily with `gca()` or get it from one of the lines in the dict (although this annoying so maybe return both might be better here)

now that i think about it, i think both is an okay compromise

Since Travis is failing and I'm not at a machine where I can easily build this, I'll have to pick this up again later.

@phobson ping!

Get folks. Sorry for the delay. When started poking around the source and tests, this was a lite more complicated than I anticipated. I hope to get to this soon. (Maybe tonight, or by the end of the week.)

## 

Paul Hobson
Sorry if this is unintelligible. I'm on my phone.

On Wed, Sep 25, 2013 at 4:59 PM, jreback notifications@github.com wrote:

> ## @phobson ping!
> 
> Reply to this email directly or view it on GitHub:
> https://github.com/pydata/pandas/pull/4472#issuecomment-25136916

The documentation seems to suggest that pandas.DataFrame.boxplot already returns a matplotlib.axes.AxesSubplot object -- but I don't believe this to be the case?

Perhaps the documentation could be updated to indicate that boxplot() currently returns a dict?

@seclinch - it'd be great if you could submit a pull request with the docs change. (which we'll revert once this current pull request is merged)

@cpcloud is this correct?

@phobson maybe a test to validate that the box plot is in fact returning a type of Axis (and not something else?)

@phobson can you rebase this

@phobson can you rebase.... @cpcloud pls review

@TomAugspurger @cpcloud 

what do you think?

@phobson can you add a doc saying how to get the dict back? Then I think good to go. 

does this fix #4636 as well?

I don't think this is ready yet. I'll have some bandwidth on friday to look
into it though. Last I remember I was having trouble groking the tests.

On Wed, Apr 9, 2014 at 5:56 AM, jreback notifications@github.com wrote:

> does this fix #4636 https://github.com/pydata/pandas/issues/4636 as
> well?
> 
> ## 
> 
> Reply to this email directly or view it on GitHubhttps://github.com/pydata/pandas/pull/4472#issuecomment-39960179
> .

Let us know if we can help. 

There's a hacky plot testing function that special cases checking the return value type of boxplot. You'll have to remove the lines that check for a dict and then the tests should pass. 

@phobson status on this?

@TomAugspurger @cpcloud 

@phobson ok....going to do this for 0.14.

See @jseabold's comment here https://github.com/pydata/pandas/issues/4264#issuecomment-41586494

I agree that box plot should always return an axes (array of axes if subplots). An optional kwarg `return_dict=False (default)`  to return a dictionary in addition to the axis will allow for more formatting.

superseded by #7096