I understand that currently they are displayed as the glyphs are created. However, I would like to change that order, since it isn’t logical for the data. I’ve been trying to change the order without success. I found one example, but not even this works. Apparently you can fix this by hand, but I haven’t found a way to 1. look into the items to see which corresponds to what and 2. actually change the order itself.
Currently using Python 3.7.3 and bokeh 1.2.0 in Jupyter notebook.
Every LegendItem has a label property corresponding to the label you set in the glyph method call. So that is how you can see what is what. As for reordering, it is a Python list, so you can re-order it in any of the standard ways, e.g with sorted and key function. Once you have a new list of the legend items in the order you want:
Thanks for the quick reply! I think I am starting to understand it. However, I still can’t get it working. Maybe a little bit of more background information might help:
I created a ColumnDataSource from a pandas data frame:
@arturomoncadatorres ah, I did not realize you were using a “GroupBy Legend”. The reason there is only one item is because the real items and their order is only computed on the JavaScript side, in the browser. I am afraid I don’t have a good suggestion for you at the moment, if you want to keep using that feature, as there are not currently any user-facing hooks or properties that would affect the default ordering that is produced now. A GitHub issue to discuss adding some user-control over the order would be appropriate.
Otherwise, you will need to construct all the legend items (one for each group) all manually, using Explicit Indices into the data columns.
Sorry for my late reply. I didn’t have time in the previous days to test this. A-ha! That works. For future reference, this is what I ended doing (pretty much what the Explicit Indices documentation indicates):
if you pass legend= to glyph methods, Bokeh will automatically add one legend. So then calling p_overall.add_layout(legend) will add another. So that seems expected. I if you are adding a legend manually then you probably don’t want to pass legend= to glyph methods (lr alternatively, if you leave then, you might want to re-configure the automatically generated legend, rather than add a new one)