Matplotlib – 使用 Python 绘制图像背景(译文)
要绘制图像背景,我们可以按照以下步骤进行:
- 从文件中将图像读入数组。
- 使用范围 [0, 300, 0, 300] 创建一个图形(fig)并添加一组子图(ax)。
- 创建一个范围 (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()输出

广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP