1

Goal

I am trying to simply plot a rectangle with a given color using matplotlib.

What I have tried

import matplotlib    

fig = plt.figure()
ax = fig.add_subplot(111)
rect = matplotlib.patches.Rectangle((50, 100), 40, 30, linewidth=1, edgecolor='r', facecolor='red')
ax.add_patch(rect)

The issue

I am getting an empty figure

enter image description here

james
  • 195
  • 1
  • 1
  • 9
  • 1
    You need to set or calculate the view limits. Line plotting functions update the limits automatically, but `add_patch` leaves them unaltered. See e.g. [this tutorial example](https://matplotlib.org/stable/gallery/shapes_and_collections/compound_path.html#sphx-glr-gallery-shapes-and-collections-compound-path-py) – JohanC Oct 23 '22 at 18:51

0 Answers0