数据可视化实操2-3

矩形的实现方法

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Rectangle

fig, ax = plt.subplots(subplot_kw={"aspect":"equal"})

x1 = np.arange(1, 2.6, 0.1)
y1 = x1 + 2

x2 = np.arange(2.5, 4.1, 0.1)
y2 = -x2 + 7

# set background color
# 调用ax.patch语句,获得类Rectangle(xy=(0,0),width=1,height=1)的实例rectangle
rectangle = ax.patch
# 设置坐标轴实例ax的背景色
rectangle.set_facecolor("lightskyblue")

# house
rectangle1 = Rectangle((1, 0), 3, 3, facecolor="w", edgecolor="rosybrown")

# door  使用参数hatch添加装饰图案“|”
rectangle2 = Rectangle((1.5, 0), 1, 1.5, facecolor="w", edgecolor="rosybrown", hatch="|||")

# window
rectangle3 = Rectangle((2.9, 1.7), 0.6, 0.6, facecolor="w", edgecolor="rosybrown")

rectangle_list = [rectangle1, rectangle2, rectangle3]

# roof line 设置屋顶的轮廓的线条颜色
ax.plot([1, 2.5, 4], [3, 4.5, 3], color="rosybrown")

# window line
ax.plot([3.2, 3.2], [1.7, 2.3], color="rosybrown")
ax.plot([2.9, 3.5], [2.0, 2.0], color="rosybrown")

# roof filled color
ax.fill_between(x1, 3, y1, color="w", interpolate=True)
ax.fill_between(x2, 3, y2, color="w", interpolate=True)

for rect in rectangle_list:
    ax.add_patch(rect)

ax.axis([0, 5, 0, 6])

plt.show()








在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值