散景等效于Matplotlib scatter_matrix [英] Bokeh equivalent of Matplotlib scatter_matrix
问题描述
在Bokeh中,是否有比下面的代码更好的方法来再现matplotlibs scatter_matrix(将所有数据绘制成所有数据):
Is there a better way of reproducing matplotlibs scatter_matrix (plot all data against all data) in Bokeh than the code below:
defaults.width = 100
defaults.height = 100
scatter_plots = []
y_max = len(dataset.columns)-1
for i, y_col in enumerate(dataset):
for j, x_col in enumerate(dataset):
df = pd.DataFrame({x_col: dataset[x_col].tolist(), y_col: dataset[y_col].tolist()})
p = Scatter(df, x=x_col, y=y_col)
if j > 0:
p.yaxis.axis_label = ""
p.yaxis.visible = False
if i < y_max:
p.xaxis.axis_label = ""
p.xaxis.visible = False
scatter_plots.append(p)
grid = gridplot(scatter_plots, ncols = len(dataset.columns))
show(grid)
特别是,我希望能够缩放和平移整个网格图作为一个实体,而不是缩放/平移鼠标悬停的子图.
In particular I would like to be able to zoom and pan the entire grid of plots as a single entity rather than zoom/pan the subplot the mouse is hovering over.
推荐答案
通常,要链接平移/缩放,您需要共享要在图之间链接的范围.《用户指南》中对此进行了说明:
In general, to have linked panning/zooming, you share the ranges that you want to be linked between plots. This is described here in the Users Guide:
https://docs.bokeh.org/en/latest/docs/user_guide/interaction/linking.html
您还可以查看此链接的SPLOM示例:
You can also check out this linked SPLOM example:
https://github.com/bokeh/bokeh/blob/master/examples/models/iris_splom.py
该示例冗长/冗长,因为它使用了低级的 bokeh.models
API.重要的部分是在创建的任何绘图上重新使用范围 xdr
和 ydr
.
That example is longer/more verbose because it uses the low level bokeh.models
API. The important part is where it re-uses the ranges xdr
and ydr
on ever plot that gets created.
在您的特定情况下,由于高级图表不预先接受范围参数(IIRC),因此我认为您必须在事后"修复图表,因此可能类似:
In your particular case, since high level charts don't accept range parameters up front (IIRC), I think you'll have to fix up the charts "after the fact", so maybe something like:
xr = scatter_plots[0].x_range
yr = scatter_plots[0].y_range
for p in scatter_plots:
p.x_range = xr
p.y_range = yr
这篇关于散景等效于Matplotlib scatter_matrix的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!