如何在 scipy.spatial.delaunay_plot_2d 中更改 matplotlib 线条颜色
How to change matplotlib line color in scipy.spatial.delaunay_plot_2d
我在 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对象的颜色:
patch.set_color('black')
您可能需要使用 draw 让您的更新可见。
我在 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对象的颜色:
patch.set_color('black')
您可能需要使用 draw 让您的更新可见。