我有一个包含PolyCollection的matplotlib
图形,该图形类似于以下内容:
我想提取颜色数据,即颜色数组(此处为黑色或白色)以及相应的x
和y
值。
作为参考,用于生成图片的代码为:
import matplotlib.pyplot as plt
from matplotlib.collections import PolyCollection
verts = []
def polygon_under_graph(xlist, ylist):
"""
Construct the vertex list which defines the polygon filling the space under
the (xlist, ylist) line graph. Assumes the xs are in ascending order.
"""
return [(xlist[0], 0.), *zip(xlist, ylist), (xlist[-1], 0.)]
# Set up the x sequence
xs = np.linspace(0., 10., 26)
ys = np.random.rand(len(xs))
verts.append(polygon_under_graph(xs, ys))
fig, ax = plt.subplots(frameon=False)
poly = PolyCollection(verts,facecolors='k',edgecolors= 'k')
ax.add_collection(poly)
我尝试使用poly.get_array()
,但未返回任何内容。
有关如何进行的任何建议?