如何以 RGB 格式将图形保存到 numpy 数组中?


若要将图形以 RGB 格式保存到 numpy 数组,我们可采取以下步骤:

  • 使用 numpy 创建rgb随机数组。

  • 合并rgb(从步骤 1 起)以形成rgb元组列表。

  • rgb转换成 numpy 数组以绘制它。

  • 绘制rgb格式的 numpy 数组。

  • 将图形保存到当前位置。

  • 若要显示图形,请使用show()方法。

示例

import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
r = np.random.rand(100)
g = np.random.rand(100)
b = np.random.rand(100)
rgb = zip(r, g, b)
arr = np.array([item for item in rgb])
plt.plot(arr)
plt.savefig("myplot.png")
plt.show()

输出

更新于: 2021 年 4 月 10 日

已浏览 1000+ 次

开启你的职业生涯

完成课程获得认证

开始吧
广告
© . All rights reserved.