python - 从包含 PolyCollection 的 matplotlib 图形中提取数据
问题描述
我有一个matplotlib
包含 PolyCollection 的图,该图类似于以下内容:
我想要的是提取颜色数据,即颜色数组(这里是黑色或白色)以及相应的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()
但没有返回任何内容。
关于如何进行的任何建议?
解决方案
推荐阅读
- python - 使用气流 PythonVirtualenvOperator 安装 linux 依赖项
- php - LARAVEL Auth::attempt 返回 false 但 Auth::check() 返回 true
- python - Python脚本无法在Heroku上创建文件夹
- r - 使用 dplyr 的列的相等性 - 缺少值的问题
- rest - 对 Web 应用程序的不同端口进行读/写访问
- linux - 从管道在环境中注册 Linux VM 在 config.sh 中失败
- bash - 错误:每当我运行 yum 时,宏 % 具有非法名称 (%define)
- sql - 如何查找一个单元格是否出现一次或多次
- autodesk-forge - 编辑访问级别时,用户对项目的访问和权限已在 BIM 360 中删除
- python - 如何根据列的值对熊猫数据框中的列进行分类?