Tick spacing with custom TickFormatter


I am trying to label plots of astronomical objects with appropriate world coordinates. Sexagesimal notation is used to label the right ascension (RA) and declination (Dec) axes.

I have created a custom TickFormatter (based upon this example) which converts the X/Y pixel coordinates to the appropriate RA/Dec values and generates the appropriate tick label strings. This all works well, but the labels overlap (see below). What is the best way to control the spacing of ticks when using a custom TickFormatter?

Thanks very much…

Your very best bet would just be to rotate the tick labels. Tick formatters have zero input into the locations of ticks, their only responsibility is to format whatever tick values are are chosen by the ticker. All the built-in tickers are listed here: tickers — Bokeh 3.2.1 Documentation These do not get much explicit use by end-users, to be honest.

If you don’t need to support zooming, then a SingleIntervalTicker might be your next best bet. If you do need to handle different scales, then maybe you could just remove one of the “nice” mantissa values from the default BasicTicker and that would work “well enough” to space things out. Failing that, it would probably be somewhat challenging to guarantee no label collistions, and possibly even require a custom extension. [1]

FWIW, for these reasons, rotating tick labels is the expected and intended way to handle this.

  1. There’s not currently a CustomJSTicker analogous to CustomJSTickFormatter though it would make sense to have one… there just has never been a big demand for it. ↩︎

Great, thanks for the instantaneous reply! Since the plot needs to zoom, I’ll rotate the X axis labels. This is a reasonable solution. I had a small hope that whatever uses TickFormatter::doFormat might adjust the number of ticks displayed or potentially recall doFormat with fewer points to make the display nice, but this would not be ideal either.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.