import numpy as np
import pandas as pd
from bokeh.objects import Range1d
from bokeh.palettes import brewer
from bokeh.plotting import (annular_wedge, line, rect,
figure, hold, show,
curplot, xgrid, ygrid, text)
figure()
hold()
df = pd.read_csv('GDP.csv', delimiter='\t', header=0, index_col=0, na_values=['..'])
t_df = df.transpose()
c_df = t_df.ix[1:, :]
ind, c = c_df.shape
k = 80 # constant
#ind = 7 #indicators
#c = 100 # countries
#values = k * np.random.random((ind, c)) #matrix
countries = t_df.columns.values
values = k * c_df.values/10
levels = np.arange(ind)
n = np.arange(c)
x = np.zeros(c)
y = np.zeros(c)
angle = 2 * np.pi / c
inner_radius = 10
width = 800
height = 800
line(x+1, y+1, alpha=0, width=width, height=height, title="GDP growth (annual %)",
tools="pan,wheel_zoom,reset,previewsave", x_axis_type=None, y_axis_type=None)
plot = curplot()
plot.x_range = Range1d(start=-1000, end=1000)
plot.y_range = Range1d(start=-1000, end=1000)
plot.background_fill = "black"
plot.outline_line_color = None
palette = brewer["Spectral"][ind]
inverted_palette = palette[::-1]
def create_ring(x, y, level, color):
annular_wedge(x, y, level * k + inner_radius, level * k + inner_radius + values[level],
n * angle, (n + 1) * angle, color=color, line_color="black")
for level in levels:
create_ring(x, y, level, palette[level])
angles = (0.5+ n) * angle
xr = (levels[-1] + 1.5) * k *np.cos(angles)
yr = (levels[-1] + 1.5) * k * np.sin(angles)
text(xr, yr, countries, angle=angles, text_font_size="7pt", text_align="left", text_baseline="middle", text_color="white")
rect([-900, -900, -900, -900, -900, -900], [900, 860, 820, 780, 740, 700], width=50, height=20,
color=inverted_palette)
text([-850, -850, -850, -850, -850, -850], [900, 860, 820, 780, 740, 700], text=t_df.index.values[1:][::-1], angle=0, text_font_size="6pt", text_align="left", text_baseline="middle", text_color="white")
show()