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)
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
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
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
References
Links | Site |
---|---|
Bokeh General visual properties | docs.bokeh.org |