Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python bokeh plot how to format axis display

Tags:

python

bokeh

the y axis ticks seem to be formatting numbers like 500000000 to 5.000e+8. Is there a way to control the display so that it displays as 500000000?

using python 2.7, bokeh 0.5.2

i m trying out the timeseries example at bokeh tutorials page

The tutorial plots 'Adj Close' against 'Date' but i'm plotting with 'Volume' against 'Date'

like image 705
Amit Avatar asked Sep 04 '14 04:09

Amit


People also ask

How do I get rid of gridlines in Bokeh?

You can hide the lines by setting their grid_line_color to None .

Is Matplotlib a Bokeh?

While Bokeh and Matplotlib both help you plot data, these two libraries are different tools for different purposes. If your focus is on website interactivity, then Bokeh is the better choice. Matplotlib, on the other hand, provides Python visualizations that integrate well with Jupyter Notebook.

How does Bokeh work Python?

Bokeh is a Python library for creating interactive visualizations for modern web browsers. It helps you build beautiful graphics, ranging from simple plots to complex dashboards with streaming datasets. With Bokeh, you can create JavaScript-powered visualizations without writing any JavaScript yourself.


2 Answers

You can also use NumeralTickFormatter as used in the toy plot below. The other possible values in place of '00' are listed here.

import pandas as pd
import numpy as np
from bokeh.plotting import figure, output_file, show
from bokeh.models import NumeralTickFormatter

df = pd.DataFrame(np.random.randint(0, 90000000000, (10,1)), columns=['my_int'])
p = figure(plot_width=700, plot_height=280, y_range=[0,100000000000])
output_file("toy_plot_with_commas")

for index, record in df.iterrows():
    p.rect([index], [record['my_int']/2], 0.8, [record['my_int']], fill_color="red", line_color="black")

p.yaxis.formatter=NumeralTickFormatter(format="00")
show(p)
like image 193
sharon Avatar answered Sep 23 '22 06:09

sharon


You have to add the option p.left[0].formatter.use_scientific = False to your code. In the timeseries tutorial, it'd be:

p1 = figure(title="Stocks")
p1.line(
    AAPL['Date'],
    AAPL['Adj Close'],
    color='#A6CEE3',
    legend='AAPL',
)

p1.left[0].formatter.use_scientific = False # <---- This forces showing 500000000 instead of 5.000e+8 as you want

show(VBox(p1, p2))
like image 36
Marc Garcia Avatar answered Sep 24 '22 06:09

Marc Garcia