Chart labels to 2 decimal places

Hello

I can’t seem to get the bar chart to label the x-axis to only 2 decimal places. Rounding the float value to 2 decimals still prints the full precision float. (Rounding to integer give me unintended consequences, such as values in same integer bin giving me > 100% results)

Here’s my code and my output. Thanks very much in advance!
Cat

···

dict = {‘values’:purity, ‘label’:ptp, “color”: colors[1]}
df = DataFrame(dict)
ax2 = Bar(df, label=‘label’, values=‘values’, color=‘color’,title=“Purity (PTP Order)”, xlabel=‘Unit PTP (uV)’, ylabel=’%’, plot_width=700, plot_height=250)


Hi Cat,

The formatting of axis tick labels is controlled by the Axis model's TickFormatter, which is available as the .formatter attribute on an Axis, e.g:
  
  myaxis.formatter

Once you have ahold of the axis you want to style, you can either configure the existing formatter, or replace it with a different one entirely, as described in the User's Guide here:

  Appearance — Bokeh 3.3.2 Documentation

As it turns out, the default tick formatter is probably configurable for the purpose you describe, via the .precision attribute:

  formatters — Bokeh 3.3.2 Documentation

It's currently a little harder to get the axis you want to modify on Charts, since they don't have convenience properties like .xaxis that Figure models do. But you can use the .select method described here:

  Appearance — Bokeh 3.3.2 Documentation

To query the plot for the objects you want, in this case something like:

  myaxes = mychart.select(type=Axis)

will return all the Axis objects as a list.

Thanks,

Bryan

···

On Jan 29, 2016, at 7:47 PM, [email protected] wrote:

Hello

I can't seem to get the bar chart to label the x-axis to only 2 decimal places. Rounding the float value to 2 decimals still prints the full precision float. (Rounding to integer give me unintended consequences, such as values in same integer bin giving me > 100% results)

Here's my code and my output. Thanks very much in advance!
Cat

****************************
dict = {'values':purity, 'label':ptp, "color": colors[1]}
df = DataFrame(dict)
ax2 = Bar(df, label='label', values='values', color='color',title="Purity (PTP Order)", xlabel='Unit PTP (uV)', ylabel='%', plot_width=700, plot_height=250)
************************

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/7c68a6a5-adfa-4dc7-a214-9c965547bf01%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.