我正在使用Bokeh.Charts.bar创建条形图。我的问题是,我有一个由15个标签组成的图例框,而这个图例框覆盖了最右边的列(我使用的是legend='top-right',如果我将其更改为'top-left',它将覆盖最左边的列)。因此,我试图创建一个图例对象(bokeh.models.annotations.relegend),以设置background_fill_data=0、label_outoff、legend_pedding等,以便移动图例框或使其透明,从而更容易创建图表。然而,到目前为止,我没有取得任何成就。非常感谢您的帮助。谢谢
bar = Bar(result_df, values='Value', label='Label', legend='bottom_right',
stack='Stack', title="Title", bar_width=0.4,
color=color(columns='Stack', palette=self.get_colors(5), tools="pan,wheel_zoom,box_zoom,reset,resize,hover")
hover = bar.select(dict(type=HoverTool))
hover.tooltips=[("Stack", "@Stack"), (field_name, "@height{" + tooltip_fmt + "}")]
legend = Legend({
"background_fill_alpha": {
"value": 0
},
"background_fill_color": {
"value": "#ffffff"
},
"border_line_alpha": {
"value": 1.0
},
"border_line_cap": "butt",
"border_line_color": {
"value": "black"
},
"border_line_dash": [],
"border_line_dash_offset": 0,
"border_line_join": "miter",
"border_line_width": {
"value": 1
},
"glyph_height": 20,
"glyph_width": 20,
"label_height": 20,
"label_standoff": 15,
"label_text_align": "left",
"label_text_alpha": {
"value": 1.0
},
"label_text_baseline": "middle",
"label_text_color": {
"value": "#444444"
},
"label_text_font": "helvetica",
"label_text_font_size": {
"value": "10pt"
},
"label_text_font_style": "normal",
"label_width": 50,
"legend_padding": 10,
"legend_spacing": 3,
"legends": [],
"level": "annotation",
"location": "top_right"
})
bar.add_legend(legend)
尝试将Bar调用中的图例kwarg设置为legend=None
。这样,这个传奇就永远不会渲染,当你添加自定义传奇时,它将是唯一的一个。不过只是一种预感。