Matplotlib – 使用 Python 绘制图像背景(译文)


要绘制图像背景,我们可以按照以下步骤进行:

  • 从文件中将图像读入数组。
  • 使用范围 [0, 300, 0, 300] 创建一个图形(fig)并添加一组子图(ax)。
  • 创建一个范围 (300) 的数组 x。
  • 使用 plot() 方法绘制 x,并设置 linestyle=dottedlinewidth=2color=red
  • 要显示图形,请使用 show() 方法。

示例

import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
im = plt.imread("bird.jpg")
fig, ax = plt.subplots()
im = ax.imshow(im, extent=[0, 300, 0, 300])
x = np.array(range(300))
ax.plot(x, x, ls='dotted', linewidth=2, color='red')
plt.show()

输出

更新时间:2021 年 5 月 6 日

19K+ 浏览量

开启你的职业生涯

通过完成课程获得认证

开始
广告
© . All rights reserved.