Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you change ticks label sizes using Python's Bokeh?

I am new to bokeh and I'm trying to plot some data in a line plot. The x-axis, y-axis and thus the ticks should have a different size than default.

Here is an example of my code:

from bokeh.plotting import figure, show
from bokeh.models import Legend, LinearAxis

import numpy as np

x = list(range(10))
y = list(range(10))

plot = figure(plot_width=900, plot_height=600)

plot.xaxis.axis_label="xaxis_name"
plot.xaxis.axis_label_text_font_size = "25pt"
plot.xaxis.axis_label_text_font = "times"
plot.xaxis.axis_label_text_color = "black"

plot.yaxis.axis_label="yaxis_name"
plot.yaxis.axis_label_text_font_size = "25pt"
plot.yaxis.axis_label_text_font = "times"
plot.yaxis.axis_label_text_color = "black"

plot.line( x, y, line_width=4, line_color='red', legend="arbitrary_line" )

plot.legend.location = "top_left"
plot.legend.label_text_font_size = "21pt"
plot.legend.label_text_font = "times"
plot.legend.label_text_color = "black"

show(plot)

This is what the output looks like:

current plot

The data is made up for this example but the idea is the same. Please note that in the current plot there is a big size different between the x axis label text and the tick numbers. All I want is to set a different size to tick labels. Any insight would be appreciated.

like image 477
leo8a Avatar asked Nov 10 '17 10:11

leo8a


1 Answers

axses have similar attributes for the major and minor tick sizes. For the major ticks are 'major_label_text_font_size'. Read the rest of the attributes at https://docs.bokeh.org/en/latest/docs/reference/models/axes.html.

from bokeh.plotting import figure, show
from bokeh.models import Legend, LinearAxis

import numpy as np

x = list(range(10))
y = list(range(10))

plot = figure(plot_width=900, plot_height=600)

plot.xaxis.axis_label="xaxis_name"
plot.xaxis.axis_label_text_font_size = "25pt"
plot.xaxis.major_label_text_font_size = "25pt"
plot.xaxis.axis_label_text_font = "times"
plot.xaxis.axis_label_text_color = "black"

plot.yaxis.axis_label="yaxis_name"
plot.yaxis.axis_label_text_font_size = "25pt"
plot.yaxis.major_label_text_font_size = "25pt"
plot.yaxis.axis_label_text_font = "times"
plot.yaxis.axis_label_text_color = "black"

plot.line( x, y, line_width=4, line_color='red', legend="arbitrary_line" )

plot.legend.location = "top_left"
plot.legend.label_text_font_size = "21pt"
plot.legend.label_text_font = "times"
plot.legend.label_text_color = "black"

show(plot)
like image 123
Anthonydouc Avatar answered Oct 29 '22 00:10

Anthonydouc