0

I would like to draw rectangle with bottom left corner at (2,3) and height and width (3,4) in matplotlib. There is a great tutorial Rectangle tutorial, but it only talks about drawing within unit square. There is even question on stackoverflow.com how to draw outside unit square stackoverflow.com, but when I ran it, it does not draw anything, it only displays axis of unit square. Plus, I am not sure why in the example we use

someX - .5, someY - .5

Any suggestions?

Community
  • 1
  • 1
user1700890
  • 7,144
  • 18
  • 87
  • 183

1 Answers1

1

The first example in the tutorial you linked works fine, you just need to rescale the axis to see the rectangle if you draw it outside of the unity square as you call it:

import matplotlib.pyplot as plt
import matplotlib.patches as patches

fig1 = plt.figure()
ax1 = fig1.add_subplot(111, aspect='equal')
ax1.add_patch(
    patches.Rectangle(
        (2, 3),   # (x,y)
        3,          # width
        4,          # height
    )
)
ax1.axis([0, 10, 0, 10])
fig1.savefig('rect1.png', dpi=90, bbox_inches='tight')

Note the ax1.axis line right before savefig command.

jwinterm
  • 334
  • 3
  • 11