question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sorting categorical axes

See original GitHub issue

Following up on https://github.com/pyviz/hvplot/issues/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?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
PeterFoghcommented, Mar 27, 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: https://github.com/holoviz/datashader/issues/596#issuecomment-389324078).

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

0reactions
MikeB2019xcommented, Aug 13, 2020

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

8.4 Changing the Order of Items on a Categorical Axis
For a categorical (or discrete) axis – one with a factor mapped to it – the order of items can be changed by...
Read more >
Categorical axes in Python - Plotly
Over 11 examples of Categorical Axes including changing color, size, log axes, and more in ... Whether using Plotly Express or not, categories...
Read more >
pandas sort x axis with categorical string values - Stack Overflow
I am trying to sort categorical variables in the pandas plot x axis. I tried sorting from pandas dataframe itself but I can...
Read more >
JET Developer Cookbook - Categorical Axis: Sorting - Oracle
Cookbook navigation. Cookbook navigation. JET. Previous Common. Hierarchical Menu button. Cookbook; Visualizations; Chart. selected.
Read more >
X-Axis Not Sorting in Categorical Order
X-Axis Not Sorting in Categorical Order. ‎02-27-2020 01:19 PM. My x-axis in the chart is going in a random order. I imagine this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found