【发布时间】: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>
到目前为止,一切都很好。然后我尝试使用 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 的原因是我想使用下拉菜单或类似的东西即时在热图的不同值源之间切换。但是,我对所使用的任何库都没有太投入,所以如果您能推荐一个更容易制作交互式热图的免费替代方案,我会很乐意研究它。
【问题讨论】:
-
MPL compat for Bokeh 依赖于不完整且不再维护的第三方库,遗憾的是。任何当前的功能都是“按原样”提供的,以防万一它有用。如果您真的想利用 Bokeh 的交互功能,我建议您直接使用本机 Bokeh API。有一些使用
bokeh.plottingAPI 的热图示例:bokeh.pydata.org/en/latest/docs/gallery/categorical.html 和bokeh.pydata.org/en/latest/docs/gallery/les_mis.html -
我认为是这样,但希望我只是错过了一些东西。感谢您的建议,我想这已经接近答案了,尽管我不相信我可以接受评论。
-
这已经不可能了。自 Bokeh 12.5(2017 年 4 月)起,support for Matplotlib has been deprecated 和
mpl.to_bokeh()已被删除。另请参阅 bryevdv 的 this Github comment
标签: python heatmap seaborn bokeh