Render a figure without any data

I’m wondering if it’s possible to render a figure without there being any data in it. The use case is that I want to show the user an empty plot which they are then able to fill with data of their own.

With the following code (modified from the code given at Providing data — Bokeh 2.3.3 Documentation):

from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource

# create a Python dict as the basis of your ColumnDataSource
data = {'x_values': [],
        'y_values': []}

# create a ColumnDataSource by passing the dict
source = ColumnDataSource(data=data)

# create a plot using the ColumnDataSource's two columns
p = figure()
p.circle(x='x_values', y='y_values', source=source)
show(p)

I get this output:

I’d like the axes/grid to be rendered so the user knows that that blank space is a graph. Basically, I want it to look like what one gets the unmodified code given at Providing data — Bokeh 2.3.3 Documentation

from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource

# create a Python dict as the basis of your ColumnDataSource
data = {'x_values': [1, 2, 3, 4, 5],
        'y_values': [6, 7, 2, 3, 6]}

# create a ColumnDataSource by passing the dict
source = ColumnDataSource(data=data)

# create a plot using the ColumnDataSource's two columns
p = figure()
p.circle(x='x_values', y='y_values', source=source)
show(p)

Which gives


I just want the scatter points to not be shown.

If I add in a line with only one data point, e.g.:

from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource

# create a Python dict as the basis of your ColumnDataSource
data = {'x_values': [],
        'y_values': []}

# create a ColumnDataSource by passing the dict
source = ColumnDataSource(data=data)

# create a plot using the ColumnDataSource's two columns
p = figure()
p.line(x=[0], y=[0])
p.circle(x='x_values', y='y_values', source=source)
show(p)

This gets me:


which is what I want. However, then I need to delete the fake line when the user loads their own data, which is very inelegant.

Is there any more elegant way to do this?

@efremdan1 By default Bokeh uses auto-ranges that compute range extents based on the glyphs that are present. Obviously, if there are no glyphs present, then it is impossible to compute any range extents, which in turn means axes cannot render. AFAIK your choices are:

  • don’t use auto ranges, i.e. explicitly set x_range and y_range yourself
  • add a glyph so that auto-ranges have something to work with (could be invisible glyph)