karolzak/ipyplot

[Feature Request] Set the order for the labels

educatorsRlearners opened this issue · 3 comments

It would be insanely useful to be able to tel ipyplot the order of the categories.

For example, I have attempting to print a list of books ordered by age. Unfortunately, even after sorting both the array of file paths and the array of labels, the pictures still come out in the wrong order.

To be clear, what I'm asking for is this:
2, 3, 4, 5, 6, 7 8, 9, 10, 11, 12, 13, 14, 15, 16, 17

instead of this:
10, 11, 12, 13, 14, 15, 16, 17, 2, 3, 4, 5, 6, 7, 8, 9

Screenshot from 2020-08-12 23-09-50

Thank you once again for this amazing tool 😄

Hi @educatorsRlearners
Most likely your problem is coming from the fact that plot_class_representations is using numpy.unique function under the hood. And numpy.unique is always sorting the results.
Now in case of strings, 12 will be sorted before 2 and that's our problem.
Here's a simple example:

# for numerical labels as strings:
np.unique(["1", "2","12"])
OUT: array(['1', '12', '2'], dtype='<U2')

# for numercial labels as ints:
np.unique([1, 12, 2])
OUT: array([ 1,  2, 12])

So as you can see the simplest workaround for your case would be to convert your labels from string to integers to keep the correct order.

Nevertheless I hear your voice and I think it makes perfect sense to add a parameter for plot_class_representations which would help to force a specific order of labels. The same features should also be available for plot_class_tabs function to define the order of tabs to be displayed.

Thanks for your feedback! Glad you like IPyPlot!

HI @karolzak,

"So as you can see the simplest workaround for your case would be to convert your labels from string to integers to keep the correct order."

Now I thought for sure I had tried to do that only to realize I hadn't 🤦‍♂️

Thank you so much and I"ll be sure to link to the project when I publish my post. Cheers!

Glad the workaround did it for you! Nevertheless I still want to add the possibility to force some specific order for classes both in plot_class_representations and plot_class_tabs so I'll keep this issue open until it's implemented, if you dont mind :)