Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Getting Your Figure Ready for Data

In this video you learn how to get you figure ready for data. The figure() object is not only the foundation of your data visualization but also the object that unlocks all of Bokeh’s available tools for visualizing data.

The code below explores just a few of the cusomization options available.

Here are some other helpful links on this topic:

  • The Bokeh Plot Class is the superclass of the figure() object, from which figures inherit a lot of their attributes.
  • The Figure Class documentation is a good place to find more detail about the arguments of the figure() object.

Here are a few specific customization options worth checking out:

  • Text Properties covers all the attributes related to changing font styles, sizes, colors, and so forth.
  • TickFormatters are built-in objects specifically for formatting your axes using Python-like string formatting syntax.

File: FirstFigure.py

# Bokeh Libraries
from bokeh.io import output_file
from bokeh.plotting import figure, show

# The figure will be rendered in a static HTML file
# called output_file_test.html
output_file('output_file_test.html', 
            title='Empty Bokeh Figure')

# Example figure
fig = figure(background_fill_color='gray',
             background_fill_alpha=0.5,
             border_fill_color='blue',
             border_fill_alpha=0.25,
             plot_height=300,
             plot_width=500,
             h_symmetry=True,
             x_axis_label='X Label',
             x_axis_type='datetime',
             x_axis_location='above',
             x_range=('2018-01-01', '2018-06-30'),
             y_axis_label='Y Label',
             y_axis_type='linear',
             y_axis_location='left',
             y_range=(0, 100),
             title='Example Figure',
             title_location='right',
             toolbar_location='below',
             tools='save')

# Remove the gridlines from the figure() object
fig.grid.grid_line_color = None

# See what it looks like
show(fig)

Comments & Discussion

Pygator on Aug. 18, 2019

you meant to import output_file in the example code. I’m already seeing a more recent version of the bokeh and how certain things have evolved like h_symmetry=True has been deprecated in my version of bokeh.

Chris Bailey RP Team on Aug. 21, 2019

Thanks for the note. I’m getting the output_file change made. Yes, it looks like they are moving along toward a version 2.

Ikones on Sept. 10, 2019

Thank you both. So what else should we use nowadays instead of h_symmetry=True for example, please?

Looking very much forward to the the update. (and aware it will take some time :-)

Ikones on Sept. 10, 2019

I am looking for the most efficient way to define a font-family for a whole figure or even plot (rather than doing it individually for the title etc. ) . Would you have any recommendations for me please?

Become a Member to join the conversation.