10

I have several curves (of different colours) plotted in the same figure and would like to widen the corresponding coloured lines in the legend so that they are easier to differentiate when projected onto a large screen.

I can access the properties of the legend fine, for example the legend's label text font size with:

p1.legend.label_text_font_size = "15pt"

where p1 is the figure in question. The problem is I don't know what the term for the "coloured lines" in the legend is and sadly the relevant section in the docs is empty.

airdas
  • 872
  • 2
  • 11
  • 19

6 Answers6

13

The following (as proposed by @ciornav) works for me in bokeh 0.13.0:

p.legend.label_text_font_size = '20pt'

as documented here.

Be careful though where you put this code. When it's e.g. between your p.figure() and p.line() statements, it will not take effect as it seems to get overridden.

Put the code after all the artifacts have been created, before p.show() or p.save().

hnhn
  • 321
  • 2
  • 7
  • Thanks for that last comment. I was wondering why it didn't work at first. The link doesn't seem to point to the right part of the docs. I see no `label_text_font_size` there. Maybe link to the [legend](https://bokeh.pydata.org/en/latest/docs/user_guide/styling.html#legends) or [text properties](https://bokeh.pydata.org/en/latest/docs/user_guide/styling.html#text-properties)? – Roald Sep 18 '18 at 06:47
12

You can view the source code on GitHub

The only search hit for 'label_text_font_size' is in this file:-

 bokeh/bokehjs/src/coffee/renderer/annotation/legend.coffee

and scroll down to the Legend class (line 113 at the time of writing this) then you can see the class attributes. Currently they are:-

 display_defaults: ->
return _.extend {}, super(), {
level: 'overlay'
border_line_color: 'black'
border_line_width: 1
border_line_alpha: 1.0
border_line_join: 'miter'
border_line_cap: 'butt'
border_line_dash: []
border_line_dash_offset: 0
label_standoff: 15
label_text_font: "helvetica"
label_text_font_size: "10pt"
label_text_font_style: "normal"
label_text_color: "#444444"
label_text_alpha: 1.0
label_text_align: "left"
label_text_baseline: "middle"
glyph_height: 20
glyph_width: 20
label_height: 20
label_width: 50
legend_padding: 10
legend_spacing: 3
orientation: "top_right"
datapoint: null
}

.. none of them stand out as being the property that you want, so it might not be possible to change it but you might like to have a play?

NB I don't think all the properties have setters so you may have to set them using something like this: p.legend.__setattr__('label_text_color', "#FF0000")

NB Bokeh is written in CoffeeScript which I have no experience of so this may all be useless.

jacanterbury
  • 1,435
  • 1
  • 26
  • 36
3

It's the glyph_height and glyph_width properties. Tested this on a scatter plot, they're by default set to 20 and 20 respectively. You can make them bigger when you build the legend item:

legend = Legend(...,
                glyph_height=30,
                glyph_width=30,
                ...)

Unfortunately, I tried setting it after the legend was already built and it doesn't seem to work...I could be wrong though.

Edit: Also, I'm using Bokeh 0.12.7

Cassian Corey
  • 133
  • 1
  • 2
  • 6
2

In the current version of Bokeh(1.2) you can change the object size in the legend by using:

p.legend.glyph_height = #some int
p.legend.glyph_width = #some int
p.show()

Make sure that you change your legend properties after youve drawn all your geometries.

J Schmidt
  • 618
  • 1
  • 6
  • 19
1

Maybe this could help:

http://docs.bokeh.org/en/0.10.0/docs/user_guide/styling.html#id4

command that should work.... just adapt your size:

p.legend.label_text_font_size = '30pt'
bigreddot
  • 33,642
  • 5
  • 69
  • 122
CVname
  • 347
  • 3
  • 12
1

As of Bokeh 0.12.6, this is not possible. Legends automatically use exactly the same visual properties (e.g. color, size width) of the thing that they are representing. So to make the line in the legend thicker, you would need to make the line itself thicker.

Being able to override things might be a reasonable request, I'd urge you to make an issue on GitHub to discuss the feature proposal:

https://github.com/bokeh/bokeh/issues

bigreddot
  • 33,642
  • 5
  • 69
  • 122