小编Mar*_*oth的帖子

检查点是否比contains_point方法更快地在椭圆内

我使用matplotlib 1.15.1,我尝试生成这样的散点图:

例

椭圆具有固定尺寸,并以中心坐标,宽度,高度和角度绘制(从外部提供):我不知道它们的等距是多少.

g_ell_center = (0.8882, 0.8882)
g_ell_width = 0.36401857095483
g_ell_height = 0.16928136341606
g_ellipse = patches.Ellipse(g_ell_center, g_ell_width, g_ell_height, angle=angle, fill=False, edgecolor='green', linewidth=2)
Run Code Online (Sandbox Code Playgroud)

这个省略号应标记我的图上的正常和半正常数据.然后,我有一个~500点的数组,必须根据它们所属的椭圆进行着色.所以我尝试用contains_point方法检查每个点:

colors_array = []
colors_scheme = ['green', 'yellow', 'black']
for point in points_array:
    if g_ellipse.contains_point(point, radius=0):
        colors_array.append(0)
    elif y_ellipse.contains_point(point, radius=0):
        colors_array.append(1)
    else:
        colors_array.append(2)
Run Code Online (Sandbox Code Playgroud)

最后,得出了一些观点:

plt.scatter(x_array, y_array, s=10, c=[colors_scheme[x] for x in colors_array], edgecolor="k", linewidths=0.3)
Run Code Online (Sandbox Code Playgroud)

但contains_point非常慢!对于300点散点图,它工作了5分钟,我必须并行生成数千个散点图.也许有更快的方法?PS整个项目绑定到matplotlib,我不能使用其他库.

python matplotlib ellipse python-3.x

9
推荐指数
1
解决办法
3654
查看次数

Make node spacing change dynamically in vis.js

I am trying to visualize some graphs. Unfortunately I often get situation when one node overlaps another, as shown below:

Setting nodeSpacing option doesn't fit me because some node labels are extremely long and some are short. Is there any option setting dynamical positioning? Here are my options:

    var options = {
         layout:{
             hierarchical: {
                 enabled:true,
                 parentCentralization: true,
                 direction: 'DU',
                 sortMethod: 'directed'
                }
         },
         edges:{
             arrows: 'from'
         }
 }
Run Code Online (Sandbox Code Playgroud)

javascript physics vis.js

1
推荐指数
1
解决办法
3682
查看次数

标签 统计

ellipse ×1

javascript ×1

matplotlib ×1

physics ×1

python ×1

python-3.x ×1

vis.js ×1