Skip to content
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

How can I plot from smallest to the largest values? #54

Open
antreask opened this issue Nov 13, 2021 · 5 comments
Open

How can I plot from smallest to the largest values? #54

antreask opened this issue Nov 13, 2021 · 5 comments

Comments

@antreask
Copy link

Hello,

I am trying to plot the bottom 10 categories from my dataset. I am changing the sort attribute to 'asc' and then it just plots the top 10 categories in ascending order,
let's say we have 5 categories e.g.
Category | Value
category 1| 1
category 2| 2
category 3| 3
category 4| 4
category 5| 5

and I want to plot (animate) the bottom 3. If I change the sort to attribute to asc then the plot is like this:
category 3| 3
category 4| 4
category 5| 5

but it should have been
category 1| 1
category 2| 2
category 3| 3

Do you have any idea how to fix this?

Thanks a lot,
Andreas

@bzimons
Copy link

bzimons commented Nov 13, 2021

Hey,

I had the same issue. I solved it by changing codes on the original package. I think you can download it, check it out, maybe it can help you!

https://github.com/bzimons/MCspeedrun

@antreask
Copy link
Author

Hi,

Thank you for the prompt response. Can you, by any chance, point me out where to look in the code?
In any case, thanks a lot for your help.

Andreas

@bzimons
Copy link

bzimons commented Nov 13, 2021

First you need to put the "bar_chart_race2" folder on the same folder that your project is. The modified code is "_make_chart.py". There are some '#' that indicates where in the code was modified. But basicaly what I did was invert the way Data is shown on the plot, the "lower" bar stays on top.

The code that uses this modified library is "rsg_barplot.py "

It's important to import the library like: import bar_chart_race2 as bcr

The code "rsg_barplot.py " basically do a clean up to the date on the data.frame, put it as the index. and create the plot.

I'm not sure if it will work well with any data, and I forgot lot of what was done. But I hope if you look carefully through the code it can help you :)

@antreask
Copy link
Author

Thanks a lot :)

@sjberkeley
Copy link

sjberkeley commented Sep 21, 2023

Thank you Beatriz! There were a number of changes in your modified version of _make_chart.py. Most of them are related to formatting of labels. The change needed to fix this reported issue is just one line. Line 893 needs to change from:

df_ranks = df_values.rank(axis=1, method='first', ascending=False).clip(upper=n_bars + 1)

to:

df_ranks = df_values.rank(axis=1, method='first', ascending=True).clip(upper=n_bars + 1)

This worked perfectly on my data. Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants