How to identify if a plot is empty

Hi,

I need to plot a procedure which let’s say consist of event1 and event2 when given a pandas Dataframe. But not every time the given Dataframe contains those two events. If the Dataframe contains none of those two events, then bokeh will generate an empty plot which is per-expected.


My question is that how can I identify if a plot is empty before I show it? So that I can avoid show an empty plot to the audience.

Something like (just a suggestion because I’m not 100% clear on the conditions)…

Check the dataframe (or even the columndatasource that it’s driving) if it meets your conditions. If it doesn’t, toggle the visibility property of the corresponding figure (e.g. f.visible = False)

“Empty” needs to be defined much more precisely. Offhand, I can think of many things “plot is empty” might mean:

  • There are no renderers present at all
  • There are renderers but they have no data
  • There are renderers, and they have data but a view is empty
  • There are renderers, and they have data but visible is False.
  • There are “visible” renderers with data but alpha is zero

And others. There’s not any one way to know ahead of time whether a plot will just “appear” empty, so you will have to refine what the actual condition leading to this is in your specific case.

Thanks, Bryan. I will verify data before pass them to Bokeh API.

1 Like