I am working on the Bokeh (0.6.1) tutorial and trying to turn off the tick marks and labels in one of the exercise plots, the scatter plot:
from __future__ import division
import numpy as np
from six.moves import zip
from bokeh.plotting import *
from bokeh.objects import Range1d
output_file("scatter.html")
figure()
N = 4000
x = np.random.random(size=N) * 100
y = np.random.random(size=N) * 100
radii = np.random.random(size=N) * 1.5
colors = [
"#%02x%02x%02x" % (r, g, 150)
for r, g in zip(np.floor(50+2*x), np.floor(30+2*y))
]
circle(x, y, radius=radii,
fill_color=colors, fill_alpha=0.6,
line_color=None, Title="Colorful Scatter")
grid().grid_line_color = None
axis().axis_line_color = None
# QUESTION PART 1: Is this the right way to turn off tick labels?
axis().major_label_text_font_size = '0pt'
# QUESTION PART 2: ...and how to turn off tick marks also?
show() # open a browser
I have managed to turn off the tick labels but no amount of searching the documentation and googling has revealed the incantation needed to turn off the tick marks.
Also I am not sure that setting axis().major_label_text_font_size
to 0pt
is the right way to turn off tick labels or if it is a kludge. Nothing else seemed to work.
Am I missing something obvious?
You can hide the lines by setting their grid_line_color to None .
By using the method xticks() and yticks() you can disable the ticks and tick labels from both the x-axis and y-axis. In the above example, we use plt. xticks([]) method to invisible both the ticks and labels on the x-axis and set the ticks empty.
This answer is an update for the more recent 0.12.4 version of Bokeh. For additional information, these commands are taken from the Styling Visual Attributes page of the Bokeh documentation.
To turn off the major and minor tick marks set their color to None
:
p = bokeh.plotting.figure(plot_width=400, plot_height=400)
p.circle([1,2,3,4,5], [2,5,8,2,7], size=10)
p.xaxis.major_tick_line_color = None # turn off x-axis major ticks
p.xaxis.minor_tick_line_color = None # turn off x-axis minor ticks
p.yaxis.major_tick_line_color = None # turn off y-axis major ticks
p.yaxis.minor_tick_line_color = None # turn off y-axis minor ticks
To turn off the tick labels set the font size to '0pt'
:
p.xaxis.major_label_text_font_size = '0pt' # turn off x-axis tick labels
p.yaxis.major_label_text_font_size = '0pt' # turn off y-axis tick labels
A similar result can be achieved by setting the font color to `None', with the disadvantage that space is still maintained for the tick labels.
p.xaxis.major_label_text_color = None # turn off x-axis tick labels leaving space
p.yaxis.major_label_text_color = None # turn off y-axis tick labels leaving space
This code snippet exemplifies removing both the major and minor tick lines and also the tick labels.
import bokeh.io
import bokeh.plotting
import bokeh.layouts
bokeh.io.output_file('remove_tick_marks.html')
p0 = bokeh.plotting.figure(plot_width=200, plot_height=200,
x_axis_label='x', y_axis_label='y',
title='original')
p0.circle([1,2,3,4,5], [2,5,8,2,7], size=10)
p1 = bokeh.plotting.figure(plot_width=200, plot_height=200,
x_axis_label='x', y_axis_label='y',
title='remove tick marks')
p1.circle([1,2,3,4,5], [2,5,8,2,7], size=10)
p1.xaxis.major_tick_line_color = None # turn off x-axis major ticks
p1.xaxis.minor_tick_line_color = None # turn off x-axis minor ticks
p1.yaxis.major_tick_line_color = None # turn off y-axis major ticks
p1.yaxis.minor_tick_line_color = None # turn off y-axis minor ticks
p2 = bokeh.plotting.figure(plot_width=200, plot_height=200,
x_axis_label='x', y_axis_label='y',
title='remove tick labels')
p2.circle([1,2,3,4,5], [2,5,8,2,7], size=10)
p2.xaxis.major_tick_line_color = None # turn off x-axis major ticks
p2.xaxis.minor_tick_line_color = None # turn off x-axis minor ticks
p2.yaxis.major_tick_line_color = None # turn off y-axis major ticks
p2.yaxis.minor_tick_line_color = None # turn off y-axis minor ticks
p2.xaxis.major_label_text_font_size = '0pt' # preferred method for removing tick labels
p2.yaxis.major_label_text_font_size = '0pt' # preferred method for removing tick labels
p3 = bokeh.plotting.figure(plot_width=200, plot_height=200,
x_axis_label='x', y_axis_label='y',
title='notice extra space')
p3.circle([1,2,3,4,5], [2,5,8,2,7], size=10)
p3.xaxis.major_tick_line_color = None # turn off x-axis major ticks
p3.xaxis.minor_tick_line_color = None # turn off x-axis minor ticks
p3.yaxis.major_tick_line_color = None # turn off y-axis major ticks
p3.yaxis.minor_tick_line_color = None # turn off y-axis minor ticks
p3.xaxis.major_label_text_color = None #note that this leaves space between the axis and the axis label
p3.yaxis.major_label_text_color = None #note that this leaves space between the axis and the axis label
grid = bokeh.layouts.gridplot([[p0, p1, p2, p3]])
bokeh.io.show(grid)
I am not sure if the absence of an answer over more than a week is due to people not knowing it, or because the question is being ignored as too obvious.
Anyway, in the hope that others might find it useful, I post this answer. I have found a way of doing it that seems so much like a hack that I am only posting it in the hope that someone will improve on it...
from __future__ import division
import numpy as np
from six.moves import zip
from bokeh.plotting import *
output_file("scatter.html")
figure()
N = 4000
x = np.random.random(size=N) * 100
y = np.random.random(size=N) * 100
radii = np.random.random(size=N) * 1.5
colors = ["#%02x%02x%02x" % (r, g, 150)
for r, g in zip(np.floor(50+2*x), np.floor(30+2*y))]
circle(x, y, radius=radii,
fill_color=colors, fill_alpha=0.6,
line_color=None, Title="Colorful Scatter")
grid().grid_line_color = None
axis().axis_line_color = None
curplot().outline_line_color = None
# Turn off tick labels
axis().major_label_text_font_size = '0pt'
# Turn off tick marks
axis().major_tick_line_color = None # turn off major ticks
axis()[0].ticker.num_minor_ticks = 0 # turn off minor ticks
axis()[1].ticker.num_minor_ticks = 0
show() # open a browser
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With