如何在scipy.spatial.delaunay_plot_2d

时间:2015-04-22 19:55:22

标签: python matplotlib

我正在使用scipy.spatial中的delaunay_plot_2d函数;稀疏文档在这里: http://docs.scipy.org/doc/scipy-dev/reference/generated/scipy.spatial.delaunay_plot_2d.html#scipy.spatial.delaunay_plot_2d

有谁知道如何更改线条颜色?默认为红色。 delaunay_plot_2d函数不接受关键字。我怀疑这是一个一般的matplotlib问题(例如,如何从图中获得线条颜色),但我无法在任何地方找到答案。谢谢!

这是一个受@ ofri-raviv启发的代码片段(尽管这一行会使行变为绿色):

import numpy as np
import matplotlib
from scipy.spatial import Delaunay, delaunay_plot_2d

x = np.random.normal(size=(10,2))
d = Delaunay(x)
h = delaunay_plot_2d(d)

再次,修改下面的@ ofri-raviv代码,这似乎有效。

for l in h.axes[0].get_children():
    if type(l) is Line2D:
        l.set_color('0.75')

每个行更改为“0.75”颜色。但那还不错。

1 个答案:

答案 0 :(得分:1)

from scipy.spatial import Delaunay, delaunay_plot_2d
x = randn(100,2)
d = Delaunay(x)
a = delaunay_plot_2d(d)
patch = [l for l in a.axes[0].get_children() if type(l) is matplotlib.patches.PathPatch][0]

然后您可以设置补丁对象的颜色:

patch.set_color('black')

您可能需要使用draw来显示您的更新。

相关问题