Search code examples
bokeh

bokeh - setting number of decimal places on axis


https://docs.bokeh.org/en/latest/docs/reference/models/formatters.html I have found the 'precision' property and it looks like this is what I want to use. I have a figure p and am trying to set the axes labels to show a specific number of decimal places. Currently, the labels look like:

1.949, 1.95, 1.951, 1.952, 1.953

But I want:

1.949, 1.950, 1.951, 1.952, 1.953

How do I actually implement this precision property to my axis label to change it?

For example, I have tried `p.models.formatters.TickFormatter.precision = 3'

And playing around with the terms after "p." but it keeps giving:

AttributeError: 'Figure' object has no attribute 'models'

The documentation on the website is confusing to me. What line do I put in my code to use this 'precision' property?

Thank you.


Solution

  • You probably want:

    from bokeh.models import NumeralTickFormatter
    
    p.xaxis[0].formatter = NumeralTickFormatter(format="0.000")
    

    The code for which is taken nearly verbatim from the User's Guide section on Tick Label Formats

    The documentation on the website is confusing to me.

    As a gentle aside, comments like this are frustrating to maintainers, because they are not actionable. There are lots of docs resources, which specific ones did you find or try to use and have problems with? What exactly did you try searching for that didn't lead you to e.g. the link above? Even if we wanted to consider trying to make some or other improvement based on your experience, there is not enough information provided in statements like this to be able to do anything.