Skip to content

geom_bar isn't allowing fractional weights #260

Closed

Description

@benlindsay

If I try to use fractional weights in a bar chart, plotnine seems to be truncating the weights to integers. For example, If I do this:

import pandas as pd
import plotnine as pn
tmp = pd.DataFrame({‘x’: [0, 1], ‘weight’: [1.5, 0.9]})
pn.ggplot(tmp) + pn.geom_bar(pn.aes(x=‘x’, weight=‘weight’))

I get

image

Whereas if I do something similar in R, like

> library(ggplot2)
> ggplot() + geom_bar(aes(x=c(0,1), weight=c(1.5, 0.9)))

I get

image

Is there any way to make that match the R functionality? Or let me know if I'm doing something wrong.

Thanks!

Activity

  1. TyberiusPrime commented on Feb 6, 2019

    @TyberiusPrime
    Contributor

    , plotnine seems to be truncating the weights to integers

    yes, yes it does: stat_count, compute_group:

      return pd.DataFrame({'count': count.astype(int),
                                 'prop': count / np.abs(count).sum(),
                                 'x': x,
                                 'width': width})

    That int cast seems to me to be the culprit - and unnecessary.
    @has2k1 what do you think?

  2. has2k1 commented on Feb 7, 2019

    @has2k1
    Owner

    @TyberiusPrime, yes that is the problem line. 832e29f is the commit that changed it.

  3. added a commit that references this issue on Feb 12, 2019
    9cc19a9
  4. benlindsay commented on Feb 13, 2019

    @benlindsay
    Author

    @has2k1 Thanks for making this change!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions