0

我试图制作美国累计冠状病毒病例的面积图。但是,面积图中没有工具提示。

面积图

如果我将面积图更改为折线图,工具提示就会出现。

折线图

如何使工具提示出现在面积图上?

这在代码中:

import pandas as pd
import numpy as np
import pandas_bokeh

df = pd.read_excel('D:/Coding Practice/data/data_corona_usa.xlsx')
df = df.iloc[::-1].reset_index()
df['Cummulative Cases'] = df['cases'].cumsum()
df['date'] = df['dateRep'].dt.strftime('%D')

pandas_bokeh.output_notebook()

df.plot_bokeh(
    kind='area',
    x= 'dateRep',
    y='Cummulative Cases',
    xlabel = 'Date',
    ylabel = 'Cummulative Cases',
    hovertool_string= r'''<h1> Date: @{date} </h1>
        <h2> Cummulative Cases: @{Cummulative Cases} </h2>''',
    title='US Corona Cases (cummulative)',
    hovertool=True,
    fontsize_title=18,
    logy=True,
    stacked=False,
    legend='top_left'
4

1 回答 1

0

我相信你的意思主要是悬停工具,面积图还不支持它,我正在使用 1.3.4 bokeh 版本,有一个新的 2. 一些东西,也许尝试更新你的 bokeh,你不会有这个问题。

这是我所做的面积图,尽管一切都按预期完成,但悬停工具也不起作用。
数据

df = pd.read_csv('BokehApp/Data/houseStock1.csv')
df = df[['Year', 'Dublin_Vacant', 'Irl_Vacant', 'Dublin_Total','Irl_Total']]
df.columns = ['Year', 'Dublin vacant', 'Ireland vacant', 'Dublin', 'Ireland']
ll = list(df.columns[1:])
source = ColumnDataSource(data=dict(x=df.Year.values,y=df['Ireland'], y1=df['Dublin'], y2=df['Ireland vacant'], y3=df['Dublin vacant']))
a2 = figure(plot_width=550, plot_height=350, title='Irish House Stock', tools = 'pan, wheel_zoom, box_zoom, reset') #, tooltips=ToolTips)
hover = HoverTool()
hover.tooltips=[('Ireland', '@y'), ('Dublin','@y1'), ('Ireland vancant', '@y2'), ('Dublin vacant','@y3')]
a2.add_tools(hover)

colors = viridis(4)
a2.varea_stack(['y3','y2','y1','y'], x='x', source=source, color=colors[::-1], legend=ll, muted_alpha=0.2)
a2.legend.location='top_left'
a2.legend.click_policy="mute"
a2.yaxis[0].formatter = NumeralTickFormatter(format="0 M")
tick_labels = {'500000':'0.5M','1000000':'1M','1500000':'1,5M','2000000':'2M','2500000':'2,5M'}
a2.yaxis.major_label_overrides = tick_labels
a2.xaxis.ticker = df.Year.values
a2.title.text_font_size = '15px'
a2.legend.background_fill_alpha=None
a2.legend.border_line_alpha=0
a2.legend.label_text_font_size = "11px"
a2.xaxis.major_label_text_font_style = 'bold'
a2.grid.grid_line_color=None
a2.toolbar.autohide = True
a2.outline_line_color=None
show(a2)
于 2020-07-16T12:47:58.450 回答