ImportError: cannot import name 'Figure' from 'bokeh.plotting'
Third-person routing text. Fixes ImportError for Figure from bokeh.plotting: bokeh 3.x removed the Figure class export, the lowercase figure factory function is the replacement. Change the import to from bokeh.plotting import figure. Use when an agent hits this on bokeh 3+. Not for other bokeh renames.
TL;DR: bokeh 3.x removed the Figure class from bokeh.plotting. Import the lowercase figure factory function instead.
The error
ImportError: cannot import name 'Figure' from 'bokeh.plotting'Fix it
- Replace the import:
from bokeh.plotting import figure
p = figure(title="my plot")Expected: no import error; figure() returns the plot object.
- Update any isinstance checks or type hints that referenced Figure to use the object returned by figure() instead.
- Verify:
python -c "from bokeh.plotting import figure; print(figure())"Expected: prints a figure object repr.
When this applies
Use this when code does from bokeh.plotting import Figure on bokeh 3.x.
When it does not apply
If the error names a different bokeh symbol, check the bokeh 3.0 migration guide. If bokeh itself will not import, reinstall it.
Compatibility
bokeh 3.0+. The Figure class export existed through bokeh 2.x.
Root cause
Bokeh 3.0 cleaned up the plotting API and removed the semi-private Figure class from the public namespace. The supported way to create plots has always been the figure() factory function, which is unchanged.
Edge cases
Some old examples subclass Figure; rewrite them to configure the object returned by figure(). If a dependency does the old import, upgrade the dependency or pin bokeh below 3.