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.

[BUG] Support unsorted/ungrouped labels for nested categorical axes

See original GitHub issue

This issues is based on the examples and discussion in https://discourse.bokeh.org/t/misalignment-of-vertical-grey-bars-for-grouped-categorical-axis/5707. Please see that thread for illustrations of the problem.

Is your feature request related to a problem? Please describe.

Currently, the grey vertical bar separating nested categories is misaligned unless the nested categories are sorted/grouped according to the outer level. This is unexpected and undocumented as far as I can tell.

Describe the solution you’d like

Either update docs to clarify or group the categories internally in bokeh. Note that the order of the categories in the plot will not change with this solution, it will just make sure that the bars are aligned and don’t overlap with the axis labels. An example of what could be done would be something like the following:

unique_tuples = df['cat_combo'].unique().tolist()
outer_order = list(dict.fromkeys(x[0] for x in unique_tuples))
grouped_unique_tuples = sorted(unique_tuples, key=lambda x: (outer_order.index(x[0]), x[1]))

Which turns the list in unique_tuples:

[('B', 'a'),
 ('A', 'a'),
 ('C', 'a'),
 ('B', 'b'),
 ('A', 'b'),
 ('C', 'b'),
 ('B', 'c'),
 ('A', 'c'),
 ('C', 'c')]

into this grouped list:

[('B', 'a'),
 ('B', 'b'),
 ('B', 'c'),
 ('A', 'a'),
 ('A', 'b'),
 ('A', 'c'),
 ('C', 'a'),
 ('C', 'b'),
 ('C', 'c')]

Describe alternatives you’ve considered Updated docs as mentioned above.

Additional context See the thread linked above.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
bryevdvcommented, Jun 17, 2020

I guess I would add: I would definitely be +1 on adding functions that make it easy to do the necessary existing-order-preserving grouping, and would even consider adding an option to have that applied automatically behind a flag that is off by default.

0reactions
joelostblomcommented, Jun 18, 2020

Thank you for clarifying @bryevdv and sorry for the miscommunication.

I would definitely be +1 on adding functions that make it easy to do the necessary existing-order-preserving grouping

This is exactly what I was trying to convey. “order-preserving grouping” is something I see little risks with and think it would be great to have a flag for this (to FactorRange I guess?). When ungrouped data is passed and the flag is not enabled I agree with you that a warning with links to docs sounds like the best solution 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Misalignment of vertical grey bars for grouped categorical axis
I am really enjoying the grouped categorical axes in Bokeh. ... opened [BUG] Support unsorted/ungrouped labels for nested categorical axes ...
Read more >
Placing Labels in nested categorical stacked bar with Bokeh ...
I can't find a way to access the numeric value where the category (2016,2017,2018) is located in the x axis. There is not...
Read more >
What's New — pandas 0.23.1 documentation - PyData |
Bug in Categorical.equals returning the wrong result when comparing two unordered Categorical arrays with the same categories, but in a different order ...
Read more >
R (and S-PLUS) Manual to Accompany Agresti's Categorical ...
This manual accompanies Agresti's Categorical Data Analysis (2002). It provides assistance in doing the statistical methods illustrated there, using S-PLUS ...
Read more >
VGAM: Vector Generalized Linear and Additive Models
Yee, T. W. (2010) The VGAM package for categorical data analysis. ... so treat the results cautiously and please report any bugs.
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