Bokeh Tutorial

1.3 Plotting - Worldmap

Exercise: Draw a worldmap with the plotting interface

Note: For your convienience, I've written a script world_countries.py that parses the XML of country polygons from the dataset: World_Country_Boundaries.csv.gz


In [1]:
# Get data
import utils.world_countries as wc
world_countries = wc.data.copy()

In [2]:
import pandas as pd
from bokeh.plotting import figure, show, output_notebook

In [3]:
# Process data
worldmap = pd.DataFrame.from_dict(world_countries, orient='index')

In [4]:
# Output option
output_notebook()


BokehJS successfully loaded.

In [5]:
# Create your plot
p = figure(plot_height=500, plot_width=900, toolbar_location="left",
    x_axis_type=None, y_axis_type=None)

p.patches(xs=worldmap['lons'], ys=worldmap['lats'], fill_color="white", fill_alpha=0,
    line_color="black", line_width=0.5)


Out[5]:
<bokeh.plotting.Figure at 0x109a124d0>

In [6]:
# Show plot
show(p)