Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] ColorBar tick labels display inappropriate precision #12618

Open
ianthomas23 opened this issue Nov 16, 2022 · 4 comments
Open

[BUG] ColorBar tick labels display inappropriate precision #12618

ianthomas23 opened this issue Nov 16, 2022 · 4 comments

Comments

@ianthomas23
Copy link
Member

Software versions

Python version : 3.10.6 | packaged by conda-forge | (main, Aug 22 2022, 20:41:22) [Clang 13.0.1 ]
IPython version : 8.5.0
Tornado version : 6.2
Bokeh version : 3.0.0+29.ga35573f0
BokehJS static path : /Users/iant/github/bokeh/src/bokeh/server/static
node.js version : v18.11.0
npm version : 8.19.2
Operating system : macOS-12.6.1-arm64-arm-64bit

Browser name and version

No response

Jupyter notebook / Jupyter Lab version

No response

Expected behavior

Better choice of numerical precision to display tick labels.

Observed behavior

Screenshot 2022-11-16 at 12 02 29

Example code

from bokeh.models import ColorBar, EqHistColorMapper
from bokeh.palettes import Blues9
from bokeh.plotting import figure, show
import numpy as np

im = np.array([[0.7, 0.7+1e-10]])

p = figure(width=300, height=300)

color_mapper = EqHistColorMapper(Blues9[::-1], rescale_discrete_levels=True)
p.image(image=[im], x=0, y=0, dw=10, dh=10, color_mapper=color_mapper)

color_bar = ColorBar(color_mapper=color_mapper)
p.add_layout(color_bar, 'right')

show(p)

Stack traceback or browser console output

No response

Screenshots

No response

@ianthomas23 ianthomas23 changed the title [BUG] ColorBar tick labels are displayed inappropriate precision [BUG] ColorBar tick labels display inappropriate precision Nov 16, 2022
@ianthomas23
Copy link
Member Author

This will need some investigation into what scenarios give good results and what give bad results. I suspect it is only ColorBars using an EqHistColorMapper that do this. ContourColorBar may do so too.

@mattpap
Copy link
Contributor

mattpap commented Nov 16, 2022

Probably you're looking for a different tick formatter, the same as you would do with any other kind axis. Or do you want fewer ticks in general?

@jbednar
Copy link
Contributor

jbednar commented Nov 16, 2022

The number of ticks seems fine to me, but I think the precision should be limited to whatever is needed to distinguish each tick from the others. I think the example above is an unusual worst case where very many decimal points are needed to distinguish values; a more typical one has ticks like 0.239, 1.980, 10.254, 100.897 where what is most useful for the user would be 0.2, 2.0, 10.2, and 100.9, i.e. enough to clearly indicate that each tick is a different level without being meaninglessly precise.

@jbednar
Copy link
Contributor

jbednar commented Nov 16, 2022

In the example above, I'm not sure if Bokeh could actually do any better, as the minimum number of decimals required for distinct representations is already precisely what's being used, so that 0.70000000000000 and 0.70000000000001 can be distinguished. But in other cases there's clearly no need for so much precision, as in this example where a single digit after the decimal would suffice:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants