How to remove grid lines from a Bokeh plot ?

Published: February 02, 2024

Updated: February 02, 2024

Tags: Python; Bokeh;

DMCA.com Protection Status

Introduction

Bokeh is an interactive data visualization library in Python that offers a wide range of tools for creating visually appealing and interactive plots. However, sometimes the grid lines on a plot can be distracting and may not add any value to the overall visual display. In such cases, it becomes necessary to eliminate or hide these grid lines from the plot.

Creating a plot with Bokeh

from bokeh.plotting import figure, show

p = figure(x_range=(-2000000, 6000000), 
           y_range=(4000000, 7000000),
           x_axis_type="mercator", 
           y_axis_type="mercator")

p.add_tile("Esri World Imagery")

show(p)

How to remove grid lines from a Bokeh plot ?
How to remove grid lines from a Bokeh plot ?

Removing grid lines from a Bokeh plot ?

Hiding all grid lines from a Bokeh plot

To remove grid lines from a Bokeh plot, you can use the grid.visible property and set it to False. This will disable all grid lines on the plot.

Code

from bokeh.plotting import figure, show

p = figure(x_range=(-2000000, 6000000), 
           y_range=(4000000, 7000000),
           x_axis_type="mercator", 
           y_axis_type="mercator")

p.add_tile("Esri World Imagery")

p.grid.visible = False  # hide grid lines

show(p)

Output

How to remove grid lines from a Bokeh plot ?
How to remove grid lines from a Bokeh plot ?

Hiding x grid lines from a Bokeh plot

Add the following line

p.xgrid.grid_line_color = None

Code

from bokeh.plotting import figure, show

p = figure(x_range=(-2000000, 6000000), 
           y_range=(4000000, 7000000),
           x_axis_type="mercator", 
           y_axis_type="mercator")

p.add_tile("Esri World Imagery")

p.xgrid.grid_line_color = None

show(p)

Output

How to remove grid lines from a Bokeh plot ?
How to remove grid lines from a Bokeh plot ?

Hiding y grid lines from a Bokeh plot

Add the following line

p.ygrid.grid_line_color = None

Code

from bokeh.plotting import figure, show

p = figure(x_range=(-2000000, 6000000), 
           y_range=(4000000, 7000000),
           x_axis_type="mercator", 
           y_axis_type="mercator")

p.add_tile("Esri World Imagery")

p.ygrid.grid_line_color = None

show(p)

Output

How to remove grid lines from a Bokeh plot ?
How to remove grid lines from a Bokeh plot ?

References

Links Site
Bokeh General visual properties docs.bokeh.org
Image

of