bokeh.charts 不见了 - 哪个库可以进行交互式彩色散点图?

bokeh.charts is gone - what library can do interactive, colored scatterplots?

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

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

我知道我可以用 seaborn 进行非交互操作:

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

我可以使用散景交互绘图,但只能在低级别上绘制,没有颜色或图例:

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

我也知道存在各种解决方法,手动定义调色板,例如 this one. However, this is ridiciously convoluted for something that used to be a simple oneliner (and still is, in R). The replacement, Holoview, does not seem to support coloring in scatterplots: Source

那么,有没有关于 Python 软件包的建议,它支持在 oneliner 中开箱即用,而不是在低级别的基础上手动编写此代码?

HoloViews library is a good replacement for the bokeh charts API. However since the API is quite unfamiliar to people who are used to imperative plotting APIs we have recently released a new library called hvPlot,它试图非常接近地反映 pandas 绘图 API,同时提供散景提供的交互性以及 HoloViews 的一些更高级的功能(例如自动分面、小部件和数据着色器集成)。要从上面重新创建情节,您可以这样做:

import bokeh.sampledata.autompg as mpg
import hvplot.pandas

mpg.autompg.hvplot.scatter(
    x='displ', y='hp', by='cyl',
    fields={'hp': 'Horsepower', 'displ': 'Displacement'},
    title='HP vs. DISPL (shaded by CYL)'
)

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

这在现代版本的 Bokeh 中实现起来非常简单:

from bokeh.plotting import figure, show
from bokeh.sampledata.iris import flowers as df
from bokeh.transform import factor_cmap

SPECIES = ['setosa', 'versicolor', 'virginica']

p = figure(tooltips="species: @species")
p.scatter("petal_length", "sepal_width", source=df, legend="species", alpha=0.5,
          size=12, color=factor_cmap('species', 'Category10_3', SPECIES))

show(p)