Matplotlib – 使用 Python 在图像背景上绘图
pythonmatplotlibserver side programmingprogramming更新于 2025/3/26 14:04:17
要在图像背景上绘图,我们可以采取以下步骤−
- 将文件中的图像读入数组。
- 创建一个图形 (fig) 并添加一组子图 (ax),范围为 [0, 300, 0, 300]。
- 创建一个范围为 (300) 的数组 x。
- 使用 plot() 方法绘制 x,其中 linestyle=dotted、linewidth=2 和 color=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()
输出

相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

