Issue
I am trying to make an image like the one below which would be made from 3 equally sized arrays that get shown only partially. Is there some way to slice or overplot the three arrays to get a division like this one?
Solution
How about using Patches
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()
Answered By - Jason M
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.