matplotlib之Rectangle

Rectangle类

class matplotlib.patches.Rectangle(
    xy, width, height, angle=0.0, **kwargs)

参数

xy: 2元组 矩形左下角xy坐标

width:矩形的宽度

height:矩形的高度

angle: float, 可选,矩形相对于x轴逆时针旋转角度,默认0

fill: bool, 可选,是否填充矩形

Rectangle实例参数对比

#-*-coding:utf-8-*-
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches

#将画布分为3*3,并且将画布定位到第一个axis系中
ax = plt.subplot(331)
ax.axis([0,5,0,5])
ax.add_patch(patches.Rectangle((0, 0), 2, 3))
ax.set_title("patches.Rectangle((0, 0), 2, 3)")


ax = plt.subplot(332)
ax.axis([0,5,0,5])
ax.add_patch(patches.Rectangle((1, 1), 2, 3))
ax.set_title("patches.Rectangle((1, 1), 2, 3)")


ax = plt.subplot(333)
ax.axis([0,5,0,5])
ax.add_patch(patches.Rectangle((1, 1), 2, 3,angle=15))
ax.set_title("patches.Rectangle((1, 1), 2, 3),angle=15")

ax = plt.subplot(334)
ax.axis([0,5,0,5])
ax.add_patch(patches.Rectangle((1, 1), 2, 3,fill=False))
ax.set_title("patches.Rectangle((1, 1), 2, 3),fill=False")

ax = plt.subplot(335)
ax.axis([0,5,0,5])
ax.add_patch(patches.Rectangle((1, 1), 2, 3,hatch="o"))
ax.set_title("patches.Rectangle((1, 1), 2, 3),hatch=o")


ax = plt.subplot(336)
ax.axis([0,5,0,5])
ax.add_patch(patches.Rectangle((1, 1), 2, 3,hatch="+"))
ax.set_title("patches.Rectangle((1, 1), 2, 3),hatch=+")

ax = plt.subplot(337)
ax.axis([0,5,0,5])
ax.add_patch(patches.Rectangle((1, 1), 2, 3,linewidth=3,edgecolor="red"))
ax.set_title("patches.Rectangle((1, 1), 2, 3),linewidth=3,edgecolor=red")

ax = plt.subplot(338)
ax.axis([0,5,0,5])
ax.add_patch(patches.Rectangle((1, 1), 2, 3,edgecolor="red",capstyle="round"))
ax.set_title("patches.Rectangle((1, 1), 2, 3),edgecolor=red,capstyle=round")

ax = plt.subplot(339)
ax.axis([0,5,0,5])
ax.add_patch(patches.Rectangle((1, 1), 2, 3,facecolor="red",alpha=0.3))
ax.set_title("patches.Rectangle((1, 1), 2, 3),facecolor=red,alpha=0.3")

plt.gcf().set_size_inches(18,10)
plt.savefig("rectangle.png")
plt.show()

图形大概像是这样子的:

rectangle

参考

matplotlib.patches.Rectangle

转载于:https://my.oschina.net/u/2474629/blog/1794898

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值