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

Sorting categorical axes #3799

Open
poplarShift opened this issue Jun 28, 2019 · 6 comments
Open

Sorting categorical axes #3799

poplarShift opened this issue Jun 28, 2019 · 6 comments
Labels
type: discussion type: enhancement Minor feature or improvement to an existing feature

Comments

@poplarShift
Copy link
Collaborator

Following up on holoviz/hvplot#122, I think we should first decide if ordering is a part of the dimension declaration or of the styling options.

One solution would be, first of all, to respect the ordering of the hv.Dimension(values= ) kwarg, that's not too hard I guess.

Beyond that, if we wanted to have ordering by, say, alphabetical, inverse alphabetical, length of label, whatever, or mean/max/etc, would that live in the styling options with a hook into redimensioning the values= kwarg accordingly? Or something different?

@poplarShift poplarShift added type: discussion type: enhancement Minor feature or improvement to an existing feature labels Jun 28, 2019
@philippjfr
Copy link
Member

philippjfr commented Jul 3, 2019

Respecting values should definitely be done, that is already outlined in #2468. Beyond that we definitely need some discussion and I wouldn't be opposed to some options to determine that. In the case of a categorical axis it may not be too weird to use xlim/ylim to set an explicit ordering for example.

@poplarShift
Copy link
Collaborator Author

Hm, I hadn't seen #3675. On the other hand I was sure I'd tested the functionality more recently than that and it still wasn't working in my case. Will have to investigate again.

@philippjfr
Copy link
Member

On the other hand I was sure I'd tested the functionality more recently than that and it still wasn't working in my case

It's definitely not implemented yet.

@DancingQuanta
Copy link
Contributor

I have this sorting issues with NdLayout/HoloMap not respecting the sort order from the original dataset in xarray.Dataset.

I did write a workaround for the meantime

def odict_sort_by_list(d, sort_list):
    return type(d)((k, d[k]) for k in sort_list) 
plot.data = odict_sort_by_list(plot.data, list)

where list is a list converted from a xr.coordinates and plot is either HoloMap or NdLayout.

@PeterFogh
Copy link

PeterFogh commented Mar 25, 2020

Problem solved - see the end of the message.

I have a similar problem of not being able re-order the axis ticks on a holoviews heatmap:

df = pd.DataFrame({
    'x': ['a', 'a', 'b', 'b'],
    'y': ['c', 'd', 'c', 'd'],
    'z': [1, 2, 3, 4]})
hv_heatmap = hv.HeatMap(df, kdims=['x', 'y'], vdims=['z'])
hv_heatmap

heatmap

Have anyone been in the same situation? And perhaps found a workaround?

I have tried @DancingQuanta' workaround of overwriting the order of hv_heatmap.data, but without any luck.

I want to change the order of the y-axis, because I'm changing my current implementation of a confusion matrix from matplotlib to holoviews, such that it gets the same format as seen here: https://scikit-learn.org/stable/auto_examples/model_selection/plot_confusion_matrix.html

EDIT
I solved the problem by using the invert_yaxis=True option flag (found it here: holoviz/datashader#596 (comment)).

df = pd.DataFrame({
    'x': ['a', 'a', 'b', 'b'],
    'y': ['c', 'd', 'c', 'd'],
    'z': [1, 2, 3, 4]})
hv_heatmap = hv.HeatMap(df, kdims=['x', 'y'], vdims=['z']).opts(invert_yaxis=True)
hv_heatmap

Anmærkning 2020-03-27 124555

@MikeB2019x
Copy link

I'm having a similar issue as I explain in a question posted on stack. The solution isn't fixed by inverting axes though. Any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: discussion type: enhancement Minor feature or improvement to an existing feature
Projects
None yet
Development

No branches or pull requests

5 participants