Problem
Only using patches.Rectangle() of plt.subplots() works properly as shown below:
from torchvision.datasets import CelebA
my_data = CelebA(
root="data",
split="all",
target_type=["bbox", "landmarks"]
)
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
fig, axes = plt.subplots(nrows=2, ncols=5, figsize=(12, 6))
for (im, ((x, y, w, h), lm)), axis in zip(my_data, axes.ravel()):
axis.imshow(X=im)
rect = Rectangle(xy=(x, y), width=w, height=h, linewidth=3, edgecolor='r', facecolor='none', clip_on=True) # Here
axis.add_patch(p=rect) # Here

And only using axes.Axes.scatter() of plt.subplots() works properly as shown below:
from torchvision.datasets import CelebA
import torchvision
my_data = CelebA(
root="data",
split="all",
target_type=["bbox", "landmarks"]
)
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from matplotlib.patches import Circle
fig, axes = plt.subplots(nrows=2, ncols=5, figsize=(12, 6))
for (im, ((x, y, w, h), lm)), axis in zip(my_data, axes.ravel()):
axis.imshow(X=im)
for px, py in lm.split(2): # Here
axis.scatter(x=px, y=py, c='#1f77b4') # Here

And only using axes.Axes.plot() of plt.subplots() works properly as shown below:
from torchvision.datasets import CelebA
import torchvision
my_data = CelebA(
root="data",
split="all",
target_type=["bbox", "landmarks"]
)
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from matplotlib.patches import Circle
fig, axes = plt.subplots(nrows=2, ncols=5, figsize=(12, 6))
for (im, ((x, y, w, h), lm)), axis in zip(my_data, axes.ravel()):
axis.imshow(X=im)
px = [] # Here
py = [] # Here
for j, v in enumerate(lm): # Here
if j%2 == 0: # Here
px.append(v) # Here
else: # Here
py.append(v) # Here
axis.plot(px, py) # Here

But using patches.Rectangle() of plt.subplots() with axes.Axes.scatter() of plt.subplots() doesn't work properly as shown below:
from torchvision.datasets import CelebA
my_data = CelebA(
root="data",
split="all",
target_type=["bbox", "landmarks"]
)
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
fig, axes = plt.subplots(nrows=2, ncols=5, figsize=(12, 6))
for (im, ((x, y, w, h), lm)), axis in zip(my_data, axes.ravel()):
axis.imshow(X=im)
rect = Rectangle(xy=(x, y), width=w, height=h, linewidth=3, edgecolor='r', facecolor='none', clip_on=True) # Here
axis.add_patch(p=rect) # Here
for px, py in lm.split(2): # Here
axis.scatter(x=px, y=py, c='#1f77b4') # Here

And using patches.Rectangle() of plt.subplots() with axes.Axes.plot() of plt.subplots() doesn't work properly as shown below:
from torchvision.datasets import CelebA
my_data = CelebA(
root="data",
split="all",
target_type=["bbox", "landmarks"]
)
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
fig, axes = plt.subplots(nrows=2, ncols=5, figsize=(12, 6))
for (im, ((x, y, w, h), lm)), axis in zip(my_data, axes.ravel()):
axis.imshow(X=im)
rect = Rectangle(xy=(x, y), width=w, height=h, linewidth=3, edgecolor='r', facecolor='none', clip_on=True) # Here
axis.add_patch(p=rect) # Here
px = [] # Here
py = [] # Here
for j, v in enumerate(lm): # Here
if j%2 == 0: # Here
px.append(v) # Here
else: # Here
py.append(v) # Here
axis.plot(px, py) # Here

So instead, I used patches.Rectangle() of plt.subplots() with patches.Circle() of plt.subplots(), then they properly work as shown below:
from torchvision.datasets import CelebA
my_data = CelebA(
root="data",
split="all",
target_type=["bbox", "landmarks"]
)
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from matplotlib.patches import Circle
fig, axes = plt.subplots(nrows=2, ncols=5, figsize=(12, 6))
for (im, ((x, y, w, h), lm)), axis in zip(my_data, axes.ravel()):
axis.imshow(X=im)
rect = Rectangle(xy=(x, y), width=w, height=h, linewidth=3, edgecolor='r', facecolor='none', clip_on=True) # Here
axis.add_patch(p=rect) # Here
for px, py in lm.split(2): # Here
axis.add_patch(p=Circle(xy=(px, py))) # Here

Proposed solution
So, it seems like matplotlib.patches works with matplotlib.patches so patches.Scatter() and patches.Plot() should be added.
Problem
Only using patches.Rectangle() of plt.subplots() works properly as shown below:
And only using axes.Axes.scatter() of
plt.subplots()works properly as shown below:And only using
axes.Axes.plot()ofplt.subplots()works properly as shown below:But using
patches.Rectangle()ofplt.subplots()withaxes.Axes.scatter()ofplt.subplots()doesn't work properly as shown below:And using
patches.Rectangle()ofplt.subplots()withaxes.Axes.plot()ofplt.subplots()doesn't work properly as shown below:So instead, I used
patches.Rectangle()ofplt.subplots()with patches.Circle() ofplt.subplots(), then they properly work as shown below:Proposed solution
So, it seems like matplotlib.patches works with
matplotlib.patchessopatches.Scatter()andpatches.Plot()should be added.