Skip to content

ENH/VIS: Dataframe bar plot can now accept width and pos keywords #6644

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
wants to merge 1 commit into from

Conversation

sinhrks
Copy link
Member

@sinhrks sinhrks commented Mar 15, 2014

Following keywords are now acceptable for dataframe.plot(kind='bar') and dataframe.plot(kind='barh').
width: Specify the bar width. In previous versions, static value 0.5 was passed to matplotlib and it cannot be overwritten.
pos: Specify relative alignments for bar plot layout. From 0 (left/bottom-end) to 1(right/top-end). Default is 0.5 (center).

Examples:
figure_1

@TomAugspurger
Copy link
Contributor

Thanks. We'll need an entry under the API section in release.rst. We have this PR for error bars: #5638. Need to check if these play well together. I'll take a look early next week.

@jreback
Copy link
Contributor

jreback commented Mar 15, 2014

@TomAugspurger iirc some convention for simply passing thru keywords on plot directly to matplotlob
isn't that right?

@sinhrks
Copy link
Member Author

sinhrks commented Mar 16, 2014

Thank you for your confirmation. I've added release note description. I'll recheck once #5638 is merged to master.

@TomAugspurger
Copy link
Contributor

@jreback We do some stuff on the pandas side before passing things through to matplotlib's ax.bar(). Right now if you pass a width= in the keyword args you get a TypeError with multiple values for width.

@sinhrks What do you think about position instead of pos? position seems to be more common in the matplotlib code. Also could you get Travis-CI hooked up so that the tests get run?

@sinhrks
Copy link
Member Author

sinhrks commented Mar 16, 2014

OK, agreed. I've changed the keyword to position and hooked to Travis-CI.

Also, I found some bar plot related dataframe tests are under TestSeriesPlot class, thus moved it to TestDataFramePlots class.

@sinhrks
Copy link
Member Author

sinhrks commented Mar 16, 2014

Travis test should have passed, but no icon seems to be displayed. Is it OK or any other configuration required?
https://travis-ci.org/sinhrks/pandas/builds/20881935

@@ -131,6 +131,10 @@ API Changes
``FutureWarning`` is raised to alert that the old ``rows`` and ``cols`` arguments
will not be supported in a future release (:issue:`5505`)

- Following keywords are now acceptable for :meth:`DataFrame.plot(kind='bar')` and :meth:`DataFrame.plot(kind='barh')`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls add to v0.14.0.txt as well

@sinhrks
Copy link
Member Author

sinhrks commented Mar 17, 2014

Thanks. Got it.

@jreback
Copy link
Contributor

jreback commented Mar 17, 2014

pls rebase and then squash as well

@sinhrks
Copy link
Member Author

sinhrks commented Mar 17, 2014

Yes, did it.

@TomAugspurger
Copy link
Contributor

Thanks, I added your note about the position argument to the plot* docstrings. Width didn't need one since it's a regular matplotlib bar argument.

@jreback
Copy link
Contributor

jreback commented Mar 19, 2014

@TomAugspurger did you mean to close?

@TomAugspurger
Copy link
Contributor

Hmm. I merged via command line since I had to move the release note down a line. Did I break something?

@jreback jreback added this to the 0.14.0 milestone Mar 19, 2014
@TomAugspurger
Copy link
Contributor

It is merged. 8d87a29

@jreback jreback closed this Mar 19, 2014
@jreback
Copy link
Contributor

jreback commented Mar 19, 2014

@TomAugspurger I see..no problem...git closes the issue automatically, but I see you just put a reference (which is correct!)

@sinhrks thanks!

@TomAugspurger
Copy link
Contributor

Thanks

@TomAugspurger
Copy link
Contributor

@jreback I see that this failed on Travis: https://travis-ci.org/pydata/pandas/jobs/21098475

Looking into it.

@TomAugspurger
Copy link
Contributor

Hmm strange. Here's the failing test:

kinds = 'line', 'bar', 'barh', 'kde', 'density'
df = DataFrame(randn(10, 2), dtype=object)
df[np.random.rand(df.shape[0]) > 0.5] = 'a'
for kind in kinds:
    with tm.assertRaises(TypeError):
        df.plot(kind=kind)

I can't reliably reproduce the failure. What does reproduce it is if I don't do the df[np.random.rand(df.shape[0]) > 0.5] = 'a' line. In that case (all numeric data, just objects) we automatically convert types and plot.

Do you think it could have randomly drawn 10 values all greater than .5? The probability is .5 ** 10 = 0.0009765625, not impossible...

I'm going to set a seed and see if it fixes.

@TomAugspurger
Copy link
Contributor

See #6670 for a hopeful fix on the last comment.

@sinhrks sinhrks deleted the bar_pr branch March 22, 2014 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants