如何让散景根据缩放比例缩放散点图大小

How to get Bokeh to scale scatter plot size according to zoom

我团队中的一些人,包括我自己,发现在 Bokeh 散点图中,例如使用 circle 方法,对于图形上数据的初始自动缩放拟合,我们感到非常迷惑可以为我们的数据拨入合理的大小,例如使用 plot.circle( x , y , size=3 )

然而,当我们以交互方式放大我们的数据时,显示的字形大小对于缩放是不变的。有没有办法让它们与我们拨入的缩放比例成比例?类似于矢量图形交互的东西(例如 svg)。如果我没记错的话,matlab 图形和 matplotlib 图形应该保持缩放比例行为。为了演示我们看到的行为,请考虑第一张图片和我在第二张图片上大致放大的红色框。

就像使用 Powerpoint 来说明所需行为的快速演示一样...

对于圆圈,设置 radius kwarg 而不是 size 值。 (其他字形类型也有类似的字形特定值)。

即:

plot.circle(x=[1,2,3], y=[1,2,3], radius=0.5)

size 总是在屏幕坐标(像素)中呈现,但是 radius 和相关属性是在数据坐标中计算的,并且应该随缩放改变幅度。

这是 Bryan Van de Ven 的一个很好的演示,显示了本次会议演讲中给出的像素坐标 (size) 和数据坐标 (radius) 之间的区别:

Bokeh 数据可视化简介 - 第 2 部分 - Strata Hadoop San Jose 2016

... the point is all of these attributes can be vectorized. We could for instance say size equals you know 2, 4, 6, 8, 10, and now the size is modulated right. So we have one that has size 2 and one that has size 4. Size is usually in pixels, radius is usually in data dimension units. But all the other ones here as well all the colors, all the visual attributes can be vectorized in this way. You can either give them a single value as we've done for instance with the line fill color, or you can give them a vector of values in which case all of the things are different.

So next exercise here you go to this notebook this is that second notebook "02 - plotting" it is to try to create the same example but now set the radius instead of the size and sort of see what's the difference if you set if you set radius instead of size.