如何在python中绘制矩形?

时间:2017-06-16 16:15:46

标签: python-3.x matplotlib seaborn

我有4分,想用它绘制矩形

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

有没有办法用matplotlib或seaborn绘制矩形?

1 个答案:

答案 0 :(得分:3)

来自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