1 回答
TA贡献1874条经验 获得超12个赞
此代码适用于 Bokeh v1.0.4。
import math
import numpy as np
import pandas as pd
from bokeh.models import ColumnDataSource, HoverTool
from bokeh.plotting import figure, show
from bokeh.palettes import Category10
df = pd.DataFrame(data = np.random.rand(10, 1), columns = ['percentage'], index = ['Func {}'.format(nmb) for nmb in range(10)])
df['color'] = Category10[10]
source = ColumnDataSource(data = dict(functions = df.index.values, percentage = df['percentage'].values, color = df['color'].values))
p = figure(x_range = df.index.values, plot_height = 600, plot_width = 800, title = "The Overall Use of my functions",
x_axis_label = 'functions', y_axis_label = 'percentage')
p.vbar(x = 'functions', top = 'percentage', width = 0.9, color = 'color', source = source)
p.add_tools(HoverTool(tooltips = '<font color=blue>@functions:</font><font color=red> @percentage</font>'))
p.xgrid.grid_line_color = None
p.xaxis.major_label_orientation = math.pi / 4 # Rotate axis' labels
show(p)
结果:
添加回答
举报