1

I have 4 points and want to plot rectangle using it

  a=[0,0]
  b=[0,5]
  c=[7,0]
  d=[7,5]

is there a way to draw rectangle using matplotlib or seaborn?

Sociopath
  • 12,395
  • 17
  • 43
  • 69

1 Answers1

10

From http://matthiaseisen.com/pp/patterns/p0203/:

a=[0,0]
b=[0,5]
c=[7,0]
d=[7,5]
width = c[0] - a[0]
height = d[1] - a[1]
lims = (0, 10)

import matplotlib.pyplot as plt
import matplotlib.patches as patches
%matplotlib inline

fig1 = plt.figure()
ax1 = fig1.add_subplot(111, aspect='equal')
ax1.add_patch(
    patches.Rectangle((0, 0), width, height))
plt.ylim(lims)
plt.xlim(lims)

enter image description here

Brad Solomon
  • 34,372
  • 28
  • 129
  • 206