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

reorder the axes within the figure #10

Closed
mnky9800n opened this issue Dec 2, 2017 · 1 comment
Closed

reorder the axes within the figure #10

mnky9800n opened this issue Dec 2, 2017 · 1 comment

Comments

@mnky9800n
Copy link

Currently the axes are ordered from low to high from top to bottom respectively. Is there a way to reverse this order? Or specify a custom order?

if you reverse data on line 390:

for i, group in enumerate(data[::-1]):

And reverse labels on line 444:

_setup_axis(a, global_x_range, col_name=labels[::-1][i], grid=ygrid)

It will reverse the order. But this seems a bit hacky, maybe there is a better way to do it?

@leotac
Copy link
Owner

leotac commented Jan 2, 2018

I think the easiest way would be to edit the input data so that they will be displayed in the order you want, rather than adding an option/changing the code.

How you do it would depend on the kind of object you are passing -- for a (non-grouped) dataframe, the order is given by the order of the columns, so you would need to reorder the columns as you like:

fig, axes = joypy.joyplot(iris)

iris_before

rev = iris[iris.columns[::-1]]
fig, axes = joypy.joyplot(rev)

iris_after

For grouped dataframes, rather than using the by argument):

fig, axes = joypy.joyplot(iris, by="Name")

iris_grouped_before

the simplest way is to pass a grouped dataframe with the groups in the desired order. This can be done by first reordering the values in the dataframe, and then grouping with sort=False:

ordered = iris.sort_values("Name", ascending=False)
grouped = ordered.groupby("Name", sort=False)
fig, axes = joypy.joyplot(grouped)

iris_grouped_after

@leotac leotac closed this as completed Jan 2, 2018
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

2 participants