31 Years of Python | 48 Hour Sale Extension!!!
days
hours
minutes
seconds

Overlapping Bar Chart Confusion

Hello dq,

I’m working through a guided project and have a basic question on plots. What I’m creating is an overlapping bar chart with three categories, ‘total’, ‘registered’ and ‘casual’, where ‘total’ is equal to ‘registered’ plus ‘casual’. When I create the overlapping bar chart I am confused with what is displayed. When you eyeball the chart it doesn’t make logical sense because it appears that ‘registered’ plus ‘casual’ is greater than the ‘total’ count when the x-axis is some function of time, ‘mnth’ or ‘weekday’. Here’s a screenshot example.

image

I’d expect the visible blue portion to be equal in size to the green bars since they should be the remainder of ‘total’ - ‘registered’, but they’re not. I did some validation of the ‘cnt’ or ‘total’ column by manually adding ‘registered’ and ‘casual’ and checking if it’s equal to the existing ‘cnt’ value, and it is. Can anyone help me understand what is going on?

Attaching the work in progress notebook, the charts start at ln12.

Thanks!
Predicting Bike Rentals.ipynb (749.5 KB)

Click here to view the jupyter notebook file in a new tab

I haven’t tried your code, so I could be wrong. But, it seems that your code is plotting the maximum value for each category grouped by month.

Run rentals.groupby("mnth")[["casual", "registered", "cnt"]].max() and look at the max values for each month. The values in the plot above seem to match up in that case. You would need to adjust your inputs based on what you want to plot given the current code is just plotting the max values for you.

This thread might be a bit relevant as well, I think.

Also, please make sure to include the link to the relevant Screen from the Classroom as well for future posts.

1 Like

That appears to be what has happened! I’ll go back and rerun to confirm. Thank you for the help.

Edit: confirmed!