您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Matplotlib:pcolormesh.get_array()返回扁平化数组-如何获取2D数据?

Matplotlib:pcolormesh.get_array()返回扁平化数组-如何获取2D数据?

数组的形状存储在私有属性_meshWidth和中_meshHeight。但是,由于这些属性不是公共API的一部分,因此,如果可能的话,保存原始数据的形状要好于依赖这些属性

import matplotlib.pyplot as plt
import numpy as np

D = np.random.uniform(0, 100, size=(5, 5))
fig, ax = plt.subplots()
h, w = D.shape
img = ax.pcolormesh( np.arange(h+1), np.arange(w+1), D)

D2 = img.get_array().reshape(img._meshWidth, img._meshHeight)
assert  np.array_equal(D, D2)

还需要注意的是,如果你想恢复原来的数组D,然后将坐标数组,np.arange(h+1)np.arange(w+1)必须有一个长度比的形状更大D。否则,当具有shape时,img.get_array()返回一个shape数组。(499, 499)``D``(500, 500)

其他 2022/1/1 18:44:36 有258人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶