简体   繁体   English

Python Bokeh条形图-修改图例框

[英]Python Bokeh Bar Chart - Modify Legend Box

I am creating a bar chart using Bokeh.Charts.Bar. 我正在使用Bokeh.Charts.Bar创建条形图。 My problem is that, I have a legend box of 15 labels, and this legend box is covering the right most column (I am using legend='top-right', it would be the same if I change it to 'top-left', it would cover the left most column). 我的问题是,我有一个由15个标签组成的图例框,该图例框覆盖了最右边的列(我使用的是legend ='top-right',如果将其更改为“ top-left-left”,则效果相同',它将覆盖最左侧的列)。 So I am trying to create a legend object (bokeh.models.annotations.legend) to set background_fill_data = 0, label_standoff, legend_pedding etc. in order to move the legend box around or make it transparent so that it is easier to create the chart. 所以我试图创建一个图例对象(bokeh.models.annotations.legend)来设置background_fill_data = 0,label_standoff,legend_pedding等,以便移动图例框或使其透明,以便于创建图表。 However, I have achieved nothing so far. 但是,到目前为止,我没有取得任何成就。 Help is really appreciated. 非常感谢您的帮助。 Thanks. 谢谢。

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)

Try setting the legend kwarg in the call to Bar as legend=None . 尝试在对Bar的调用中将图例kwarg设置为legend=None That way, that legend never renders and when you add your custom one, it will be the only one. 这样,该图例将永远不会呈现,并且当您添加自定义图例时,它将是唯一的图例。 Just a hunch though. 不过只是预感。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM