Can't "hide" or remove a Text glyph


I have some text that i display in my plot to warn user that there is no data yet to show, when the data is fetched, i just want to remove / hide those text glyphs.

I tried many ways, from my understanding of Bokeh, Text is a glyph, so it’s a model, so it’s supposed to have a “visible” attribute, but i can’t find it. I think i misunderstand with a renderer…

when trying to make a : myglyph.update(visible=False)
I get the following:

ERROR:  unexpected attribute 'visible' to Text, 
possible attributes are angle, angle_unit, js_property_callbacks, name, subscribed_events, tags, text,
 text_align, text_alpha, text_baseline, text_color, text_font, text_font_size, text_font_style, 
text_line_height, x, x_offset, y or y_offset 

Thanks a lot if you can explain what i’m clearly missing !


The error message is showing you what attributes exist for your text glyph. You can also see current values for the properties with myglyph.properties_with_values().

If myglyph is of type bokeh.models.glyphs.Text, you have a few options if you simply want to hide/unhide the text.

  1. Set the text_alpha property to 0.0, this will make the text completely transparent and gone from the user’s perspective.

  2. Work with the glyph renderer, which can get obtained when you’re assigning it to the figure. For example, if p is the name of a figure, in an illustrative example …

r = p.add_glyph(myglyph)

will assign the result of the glyph assignment to the variable r, which is of type bokeh.models.renderers.GlyphRenderer.

The glyph renderer, r, has a visible property which can be set to True or False. (Note: the renderer also has a level property in case you want to overlay or underlay it w.r.t. other objects.)

1 Like

Thanks a lot, this clears up things for me !


I come back to this post because i used your answer to make something that “kind of works” by hiding glyphs, hoping to get a grasp on some details in the meantime but i now end up with a solution that is too messy for production.

I do dynamic loading of data/glyphs into plots with some large datasets, and the solution of “emptying” the column Datasource doesn’t cover all my needs, since some of my figures are using a customized routine before the bokeh logic, and hooking up the correct callbakcs in those special cases would be spaghetti.

To give you some context, here is the piece of code i use: (btw i’m in server configuration for web embeding)

def empty_figure(self): = {}   

     for renderer in self.p.renderers:
         renderer.visible = False

This does the trick but now i end up having my “click to hide” legends appear greyed out and it isn’t fixed by adding new glyphs, AND i get the intuition that my data is still in client’s memory, which would be an issue if this added up many times.

So, My questions are:

Is there a clean way to really REMOVE a glyph (line, point, histogram, rgba image) from a figure ?

If not, what are the implications of just hiding with the visible atribute ? Will this take memory in client’s browser ?

Is it possible to display a trully empty figure, without having to use a hack around invisible glyphs (They mess up with auto-scaling) ?

Thanks a lot and of course i can provide code or screenshots if my description isn’t clear enough

Not really. Glyphs (or really, their GlyphRenderers) might be referenced from: legends, from auto-ranges, hover tools, arbitrary user-defined CustomJS args dicts, or from custom extensions that BokehJS itself knows nothing about. Removing is not a common need at all, and actually cleaning up all the connections would be very hard to get right (if not impossible in the general case, e.g. in the presence custom extensions) so we simply advise different usage patterns.

If not, what are the implications of just hiding with the visible atribute ? Will this take memory in client’s browser ?

Certainly but the glyph itself (and its GlyphRenderer) are very small objects. Unless you are talking about thousands or tens of thousands of them, what would usually matter much more is the data source. If you suspect clearing out a dict somehow does not release memory, that is something that would need to be investigated and documented with a real profiler.

Is it possible to display a trully empty figure , without having to use a hack around invisible glyphs

Certainly, you just have to set the range start/end manually yourself. Auto-ranging requires having something present on which to determine the range extents.


Thank you !

1 Like