第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何設(shè)置條形圖懸停以顯示 x 軸的標(biāo)簽?

如何設(shè)置條形圖懸停以顯示 x 軸的標(biāo)簽?

慕碼人2483693 2021-12-17 16:05:22
我已經(jīng)生成了一個簡單的條形圖。為了使其更具交互性,我在圖表中添加了 Hovertool。from bokeh.io import show, output_notebookfrom bokeh.plotting import figure, output_filefrom bokeh.models.glyphs import HBarfrom bokeh.models import ColumnDataSource, Legend, HoverTooloutput_notebook()# Set x and yfunctions = ['func_1', 'func_2', 'func_3']percentage = [233.14, 312.03, 234.00]# Set data source (color needs to be set precisely with len(category))source = ColumnDataSource(data=dict(functions=functions, percentage=percentage))# Set the x_range to the list of categories abovep = figure(x_range=functions, plot_height=600, plot_width=800, title="The Overall Use of my functions",          x_axis_label='Functions', y_axis_label='Percentage')# Categorical values can also be used as coordinatesp.vbar(x='functions', top='percentage', width=0.9, source=source)p.add_tools(HoverTool(tooltips=[('Percentage', "@percentage")]))show(p)雖然它正確顯示了 y 軸的值,但我想顯示 x 軸的標(biāo)簽(例如,F(xiàn)unc1:9.45)。就像鏈接中顯示的圖片一樣(我還不能發(fā)布圖片):更新#1 我試圖想出一些東西,這就是我得到的:# Set Hoverpercentage = list(map(lambda i: str(i), percentage))my_hover = list(zip(functions, percentage))p.add_tools(HoverTool(tooltips=my_hover))事實(shí)證明它顯示了每個條中的每個細(xì)節(jié),如下所示
查看完整描述

1 回答

?
HUWWW

TA貢獻(xiàn)1874條經(jīng)驗(yàn) 獲得超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)

結(jié)果:

http://img1.sycdn.imooc.com//61bc44f7000101a808240600.jpg

查看完整回答
反對 回復(fù) 2021-12-17
  • 1 回答
  • 0 關(guān)注
  • 188 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號