[Python + Bokeh 0.12.5]:如何制作密度图?

时间:2017-05-03 13:31:01

标签: python bokeh

我正在尝试Bokeh,但找不到任何密度图的参考。

此示例(使用ggplot)适用于Bokeh 0.11,并已从最后一个Bokeh版本的库中删除: http://bokeh.pydata.org/en/0.11.0/docs/gallery/density.html

在Bokeh 0.12.5上它没有用,因为ggplot 0.11没有任何draw()方法。

它是原生实现还是有解决方法?

提前谢谢。

1 个答案:

答案 0 :(得分:1)

from ggplot import aes, diamonds, geom_density, ggplot
import matplotlib.pyplot as plt

正如@bigreddot所说,我们可以删除这一行:
来自bokeh import mpl的

from bokeh.plotting import output_file, show

g = ggplot(diamonds, aes(x='price', color='cut')) + geom_density()
g.show()

plt.title("Density ggplot-based plot in Bokeh.")

output_file("density.html", title="density.py example")

show(mpl.to_bokeh())

enter image description here