Python散景条形图-修改图例框
Python Bokeh Bar Chart - Modify Legend Box
我正在使用 Bokeh.Charts.Bar 创建条形图。我的问题是,我有一个 15 个标签的图例框,这个图例框覆盖了最右边的列(我使用的是 legend='top-right',如果我将其更改为 'top-left',它将覆盖最左边的列)。所以我正在尝试创建一个图例对象 (bokeh.models.annotations.legend) 来设置 background_fill_data = 0、label_standoff、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
。这样,该图例永远不会呈现,当您添加自定义图例时,它将是唯一的图例。不过只是预感。
我正在使用 Bokeh.Charts.Bar 创建条形图。我的问题是,我有一个 15 个标签的图例框,这个图例框覆盖了最右边的列(我使用的是 legend='top-right',如果我将其更改为 'top-left',它将覆盖最左边的列)。所以我正在尝试创建一个图例对象 (bokeh.models.annotations.legend) 来设置 background_fill_data = 0、label_standoff、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
。这样,该图例永远不会呈现,当您添加自定义图例时,它将是唯一的图例。不过只是预感。