import cv2
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Rectangle
linestyle_str = [
('solid', 'solid'), # Same as (0, ()) or '-'
('dotted', 'dotted'), # Same as (0, (1, 1)) or ':'
('dashed', 'dashed'), # Same as '--'
('dashdot', 'dashdot')] # Same as '-.'
linestyle_tuple = [
('loosely dotted', (0, (1, 10))),
('dotted', (0, (1, 1))),
('densely dotted', (0, (1, 1))),
('long dash with offset', (5, (10, 3))),
('loosely dashed', (0, (5, 10))),
('dashed', (0, (5, 5))),
('densely dashed', (0, (5, 1))),
('loosely dashdotted', (0, (3, 10, 1, 10))),
('dashdotted', (0, (3, 5, 1, 5))),
('densely dashdotted', (0, (3, 1, 1, 1))),
('dashdotdotted', (0, (3, 5, 1, 5, 1, 5))),
('loosely dashdotdotted', (0, (3, 10, 1, 10, 1, 10))),
('densely dashdotdotted', (0, (3, 1, 1, 1, 1, 1)))]
fname = "img.tiff"
img = cv2.cvtColor(cv2.imread(fname), cv2.COLOR_BGR2RGB)
h_min, h_max = 50, 150
w_min, w_max = 350, 450
fig, ax = plt.subplots()
ax.imshow(img)
# add rectangle to plot
rect = Rectangle((w_min, h_min), 100, 100, linewidth=2, edgecolor='blue',
facecolor='none',
linestyle=(0, (5, 5)))
ax.add_patch(rect)
plt.savefig("img.pdf")
plt.show()
常见的线条款式: