python - bokeh.charts 消失了 - 什么库可以制作交互式彩色散点图?

标签 python plot bokeh scatter-plot

我发现自己最常做的可视化之一如下:我有 x,y 数据,按类别标记。我需要将其绘制在散点图中,根据标签自动为点着色,并生成图例。 可视化应该是交互式的(可缩放、将鼠标悬停在点上显示元数据等...)

这是我正在寻找的完美示例 - 现已弃用的 bokeh.charts library 中存在的东西:

enter image description here

我知道我可以与seaborn以非交互方式完成此操作:

fig = sns.lmplot(x="Length", y="Boot", hue="class", fit_reg=False, data=df)

我可以与 Bokeh 交互地绘制,但只能在较低的水平上,没有颜色或图例:

p = Scatter(df, x="Length", y="Boot", plot_width=800, plot_height=600, 
    tooltips=TOOLTIPS, title="Cars")

我也知道存在各种解决方法,手动定义调色板,例如 this one 。然而,对于曾经是简单的单行代码(在 R 中仍然如此)的东西来说,这是极其复杂的。替代品 Holoview 似乎不支持散点图中的着色:Source

那么,对于在 oneliner 中支持开箱即用的 Python 包有什么建议,而不是在低级别上手动编写此代码吗?

最佳答案

HoloViews库是 Bokeh 图 API 的一个很好的替代品。然而,由于习惯了命令式绘图 API 的人对该 API 相当陌生,我们最近发布了一个名为 hvPlot 的新库。 ,它试图非常接近地反射(reflect) pandas 绘图 API,同时提供 Bokeh 提供的交互性以及 HoloViews 的一些更高级的功能(例如自动分面、小部件和数据着色器集成)。要从上面重新创建绘图,您可以执行以下操作:

import bokeh.sampledata.autompg as mpg
import hvplot.pandas  # adds hvplot method to pandas objects

myPlot = mpg.autompg.hvplot.scatter(
        x='displ', y='hp', by='cyl',
        fields={'hp': 'Horsepower', 'displ': 'Displacement'},
        title='HP vs. DISPL (shaded by CYL)'
)
hvplot.show(myPlot) # view the plot in a browser (hvplot doesn't support modal dialogs)

enter image description here

请注意,在下一版本中,您将能够将 fields 参数替换为更明确的 xlabelylabel 参数。

关于python - bokeh.charts 消失了 - 什么库可以制作交互式彩色散点图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51675927/

相关文章:

python - 是否可以使用有序字典或列表进行绘图,OrderedDict 不起作用

python - Bokeh 服务器 - 如何在回调函数中操作选择

python - Holoviews散点图的回归线?

python - python语法错误中的方程式求解器

python - 使用 ortools 选择列表中两个最小的整数值

python - 使用文件作为stdin在python中执行shell命令

java - 在 PyLucene 中实现自定义相似度

python - 使用 matplotlib 和 python 绘制 datetime.timedelta

python - 在 matplotlib pcolor 中设置颜色