【问题标题】:Outputting a Seaborn heatmap chart of a pandas DataFrame using Bokeh使用 Bokeh 输出 pandas DataFrame 的 Seaborn 热图图表
【发布时间】:2016-11-13 13:38:25
【问题描述】:

我正在尝试绘制 Seaborn 热图并使用 Bokeh 输出。

这是我绘制图表的方式:

In [1]: import pandas as pd
   ...: import seaborn as sns
   ...: 
   ...: df = pd.DataFrame([['item1',1,2,3,4,'SEPT'],
   ...:                    ['item2',5,6,7,8,'OCT'],
   ...:                    ['item3',9,10,11,12,'SEPT'],
   ...:                    ['item1',13,14,15,16,'OCT'],
   ...:                    ['item2',17,18,19,20,'SEPT'],
   ...:                    ['item3',21,22,23,24,'OCT']],
   ...:                    columns = ['itemName','metric1',
   ...:                    'metric2','metric3','metric4','Month'])
   ...: df
Out[1]: 
  itemName  metric1  metric2  metric3  metric4 Month
0    item1        1        2        3        4  SEPT
1    item2        5        6        7        8   OCT
2    item3        9       10       11       12  SEPT
3    item1       13       14       15       16   OCT
4    item2       17       18       19       20  SEPT
5    item3       21       22       23       24   OCT

In [2]: df1 = df.pivot(index='itemName',columns='Month',values='metric1')
   ...: 
   ...: df1
Out[2]: 
Month     OCT  SEPT
itemName           
item1      13     1
item2       5    17
item3      21     9

In [3]: sns.heatmap(df1, annot=True)
Out[3]: <matplotlib.axes._subplots.AxesSubplot at 0x2a3836cc2b0>

Resulting image

到目前为止,一切都很好。然后我尝试使用 Bokeh 输出图表,使用 example 作为基础:

In [4]: from bokeh import mpl
   ...: from bokeh.plotting import output_file, show

In [5]: output_file("seaborn_heatmap.html", title="seaborn heatmap example")

In [6]: show(mpl.to_bokeh())
WARNING:C:\Users\<Username>\Anaconda3\lib\site-packages\bokeh\core\validation\check.py:W-1001 (NO_DATA_RENDERERS): Plot has no data renderers: Plot, ViewModel:Plot, ref _id: b78fd176-bffd-4fd0-9b7c-a169d299f541

这会导致图表为空。我做错了什么?

附:使用 Bokeh 的原因是我想使用下拉菜单或类似的东西即时在热图的不同值源之间切换。但是,我对所使用的任何库都没有太投入,所以如果您能推荐一个更容易制作交互式热图的免费替代方案,我会很乐意研究它。

【问题讨论】:

标签: python heatmap seaborn bokeh


【解决方案1】:

您所要求的内容不受支持且不存在。在 Bokeh 或 Matplotlib 中,没有将 Matplotlib 输出转换为 Bokeh 输出的特性或功能。因此,这个问题的答案是:

你所要求的是不可能的。

(作为 Bokeh 的共同创建者和主要维护者 5 年以上)重要的是,用户必须清楚明确地了解将 MPL 转换为 Bokeh 没有“灵丹妙药”。其他任何内容都是错误信息

生成 Bokeh 输出的唯一选择是直接使用本机 Bokeh API,例如bokeh.plotting API。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-21
    • 2016-11-03
    • 2017-08-18
    • 2012-08-30
    • 2020-10-16
    • 1970-01-01
    • 2021-03-25
    • 2016-12-01
    相关资源
    最近更新 更多