【发布时间】:2016-03-08 06:42:51
【问题描述】:
我想将 matplotlib 图形作为 3 维 RGBA 数组。我正在使用以下代码进行转换:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
canvas = np.zeros((20, 20))
img = plt.imshow(canvas, interpolation='none').make_image()
h, w, d = img.as_rgba_str()
print(h,w)
rgba_array = np.fromstring(d, dtype=np.uint8).reshape(h, w, 4)
plt.imshow(rgba_array)
Out[1]: (249, 373)
<matplotlib.image.AxesImage at 0x111fa8b10>
为什么长宽比与原来的方形阵列不同?有没有我可以指定的参数或替代方法来获取图形的原始形状的 rgba 数组?
【问题讨论】:
标签: python arrays matplotlib