python - Python:将三个图像合二为一地显示前后
解决方案
如何使用补丁
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import matplotlib.lines as lines
import os
patch1 = ((0,0.3),(0,1),(0.5,1),(0.5,0.5))
patch2 = ((0.5,0.5),(0.5,1),(1,1),(1,0.3))
patch3 = ((0,0),(0,0.3),(0.5,0.5),(1,0.3),(1,0))
# Pictures from Win10 in WSL2
path = r"/mnt/c/Windows/Web/Wallpaper/Theme1"
img1 = plt.imread(os.path.join(path, "img1.jpg"))
img2 = plt.imread(os.path.join(path, "img2.jpg"))
img3 = plt.imread(os.path.join(path, "img3.jpg"))
fig, ax = plt.subplots()
poly1 = patches.Polygon(patch1, transform=ax.transAxes)
poly2 = patches.Polygon(patch2, transform=ax.transAxes)
poly3 = patches.Polygon(patch3, transform=ax.transAxes)
ip1 = ax.imshow(img1)
ip2 = ax.imshow(img2)
ip3 = ax.imshow(img3)
ip1.set_clip_path(poly1)
ip2.set_clip_path(poly2)
ip3.set_clip_path(poly3)
l1 = lines.Line2D((0, 0.5), (0.3, 0.5), color="w", transform=ax.transAxes)
l2 = lines.Line2D((0.5, 0.5), (0.5, 1), color="w", transform=ax.transAxes)
l3 = lines.Line2D((0.5, 1), (0.5, 0.3), color="w", transform=ax.transAxes)
l1.set_linewidth(5)
l2.set_linewidth(5)
l3.set_linewidth(5)
fig.add_artist(l1)
fig.add_artist(l2)
fig.add_artist(l3)
ax.axis('off')
plt.show()
推荐阅读
- asp.net - 阻止 ASP.NET Core cookie-authentication 接受为不同主机名签名的 cookie
- aerospike - Aerospike python 客户端:只返回 bins 数据(没有关键细节和元数据)
- angular - 是否存在不需要初始值且能够提供当前值的 BehaviorSubject 等效项?
- c# - 如何在 LINQ - SQL 中选择 Null
- r - 用 c() 和 as.vector 创建向量有什么区别?
- python - 如何创建一个 numpy 张量
- c - 如何在 C 中打印 u16 数组?
- c++ - 为什么我收到此错误以及如何解决?
- javascript - 无效重定向:当授权重定向 URI 用于 Google 客户端 ID Web 应用时,使用禁止域
- sql - 计数以将多个列作为 SQL 查询返回