从包含PolyCollection的matplotlib图中提取数据

时间:2019-04-18 09:37:50

标签: python matplotlib

我有一个包含PolyCollection的matplotlib图形,该图形类似于以下内容:

Figureforextraction

我想提取颜色数据,即颜色数组(此处为黑色或白色)以及相应的xy值。

作为参考,用于生成图片的代码为:

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(),但未返回任何内容。

有关如何进行的任何建议?

0 个答案:

没有答案