How can I make legend outside plot area with stacked bar

你。 提交于 2019-12-02 08:04:11

The way I've solved this is as follows (example for hbar stack but the solution is identical)

# make a figure
p = figure(y_range=uniquesubjects, x_range=(0,600), plot_height=900, plot_width=900, title="Subjects In Trouble!",
        toolbar_location=None, tools="")

# add stacked horizontal bars
p.hbar_stack(headers[0:-1], y='subject_name', color=colors, height=1, source=source, legend=[value(x) for x in legendvals])

# add some graph options
p.xgrid.grid_line_color = None
p.axis.minor_tick_line_color = None
p.outline_line_color = None
p.legend.location = "top_right"
p.legend.orientation = "vertical"

new_legend = p.legend[0]
p.legend[0].plot = None
p.add_layout(new_legend, 'right')

show(p)

I create an "internal legend", as normal and then I take a copy of it, remove it from the original location and add it as a layout outside. This is done in these three lines:

new_legend = p.legend[0]
p.legend[0].plot = None
p.add_layout(new_legend, 'right')
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!