☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Thinning of CategoricalAxes tick labels

Community Supportbokeh
dinya
dinya

Hello,

I have a plot that has some ordered sequence of strings (say, serial numbers of experiments) at x-axis. The sequence can be mapped to a (continuous?) integer series.

As far as I understand, CategoricalAxes are usually used for this.

Unfortunately, when there are a lot of such categories, visual overlap occurs.

Is there any “idiomatic way” for visual thinning of xticklabels for CategoricalAxes at current scale (like for DateTimeAxis or LinearAxis) so that recalculation to a new scale occurs when zooming?

Moreover I think the LinearAxis is more suitable if the mapping like {int xvalue : str view} is possible.

⌁   Link to post
Jonas_Grave_Kristens
Jonas_Grave_Kristens

@dinya Have you tested major_label_overrides? (link). Maybe that can be used.

The example below use idx field in the CDS as x values (integers) for placing the data, but uses the x field for the axis label.

import numpy as np
from bokeh.io import output_file, save
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource

output_file('page.html')

alpha = list('abcdefghijklmnopqrstuvwxyz')
data = {
    'x': alpha,
    'idx': list(range(len(alpha))),
    'y': np.random.rand(len(alpha))
}

src = ColumnDataSource(data = data)

p = figure(width = 300)
p.circle(x = 'idx', y = 'y', alpha = 0.7, source = src)

p.xaxis.major_label_overrides = {
    i: a for i, a in zip(data['idx'], data['x'])
}
p.xaxis.minor_tick_line_color = None

save(p)
⌁   Link to post
Bryan
Bryan

Just circling back to note that the next version 3.6 will add a CustomJSTicker that can be used to adjust categorical ticks

⌁   Link to post

End of archived discussion · Replies are disabled