# Can't order legend entries in hbar plot

**URL:** <https://discourse.bokeh.org/t/cant-order-legend-entries-in-hbar-plot/3816>\
**Category:** Community Support\
**Created:** [July 28, 2019, 10:17pm UTC](https://discourse.bokeh.org/t/cant-order-legend-entries-in-hbar-plot/3816 "2019-07-28T22:17:20Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![arturomoncadatorres](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/arturomoncadatorres/32/1029_2.png) [@arturomoncadatorres](https://discourse.bokeh.org/u/arturomoncadatorres)\
**Post date:** [August 1, 2019, 11:16pm UTC](https://discourse.bokeh.org/t/cant-order-legend-entries-in-hbar-plot/3816/8 "2019-08-01T23:16:25Z")

</div>

Gotcha. In case someone comes across this post looking for a solution, the final chunk of code looks like this:

```auto
# Define source
source = ColumnDataSource(df[['name', 'count', 'type']])

# Create figure
p = figure(y_range=FactorRange(factors=name, bounds=(0, len(name))))
r = p.hbar(y='name', left=0, right='count', height=0.9, source=source)

# Add legend
legend = Legend(items=[
    LegendItem(label='1', renderers=[r], index=6),
    LegendItem(label='2', renderers=[r], index=37),
    LegendItem(label='3', renderers=[r], index=1),
    LegendItem(label='4', renderers=[r], index=10),
    LegendItem(label='5', renderers=[r], index=2),
    LegendItem(label='6', renderers=[r], index=14),
    LegendItem(label='7', renderers=[r], index=8),
], title='Type', location='bottom_right')
p.add_layout(legend)

```

where the indexes were obtained manually (can probably be done programatically).

---

_[View the full topic](https://discourse.bokeh.org/t/cant-order-legend-entries-in-hbar-plot/3816)._
