Inspecting Figure and get annotations

Hello, I am trying to access the annotations in a figure.

The reference guide says that p.renderers gives “A list of all renderers for this plot, including guides and annotations in addition to glyphs.”

However, it seems to me that it only gives the glyph renderers.

How can I access the arrow renderer in this case?

from bokeh.models import Arrow, NormalHead, OpenHead, VeeHead
from bokeh.plotting import figure, output_file, show

output_file("arrow.html", title=" example")

p = figure(width=600, height=600)[0, 1, 0.5], y=[0, 0, 0.7], radius=0.1,  color="navy")

p.add_layout(Arrow(end=OpenHead(line_color="firebrick", line_width=4),
                   x_start=0, y_start=0, x_end=1, y_end=0))

p.line([0.2, 0.2, 0.2, 0.2, 0.2], [0.1, 0.2, 0.3, 0.4, 0.5])

print(len(p.renderers)) # Gives 2 the circles and lines

That helpstring was probably written ten years ago, when it was true at the time. At some point later things were changed to store “layouts” in individual properties for each layout location:

In [4]:
Out[4]: [Grid(id='1014', ...), Grid(id='1018', ...), Arrow(id='1040', ...)]

If you are able to submit a pull request to update the helpstring text, that would certainly be helpful and appreciated.

Thank you, @Bryan. I went ahead and submitted a PR #12512

1 Like