[BUG] Support unsorted/ungrouped labels for nested categorical axes
See original GitHub issueThis 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:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
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.
Thank you for clarifying @bryevdv and sorry for the miscommunication.
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 👍