如何在scipy.spatial.delaunay_plot_2d中更改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"。但这已经足够了。

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来使您的更新可见。

最新更新