python绘制禁掉区范围

import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle

# 读取数据
data=pd.read_csv(r'D:\temp\工作簿2.csv',encoding='utf-8')

prohibitedCount=1 # 设置禁吊区数量,默认data最后的几行为禁掉区

# 创建图形和轴
fig, ax = plt.subplots()
x=[]

# 遍历每行数据并绘制矩形
for index, row in data.iterrows():
    # 提取左下和右上坐标
    left_bottom = (row['addr_x_fr'], row['addr_y_fr'])
    right_top = (row['addr_x_to'], row['addr_y_to'])
    x.append(index)
    # 计算矩形的宽度和高度
    width = right_top[0] - left_bottom[0]
    height = right_top[1] - left_bottom[1]
    
    # 创建矩形对象
    if index<=len(data)-prohibitedCount-1:
        rect = Rectangle(left_bottom, width, height, linewidth=1, edgecolor='blue', facecolor='none')
    else:
        rect = Rectangle(left_bottom, width, height, linewidth=1, edgecolor='r', facecolor='none')
    
    # 将矩形添加到轴上
    ax.add_patch(rect)

# 设置轴的范围
# 设置轴的范围
ax.set_xlim(0, 320000)
ax.set_ylim(0, 36000)
ax.set_aspect('equal')


plt.savefig('rectangles_2.svg', format='svg')  # 保存为SVG格式的矢量图


# 显示图形
plt.show()

在这里插入图片描述

  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weixin_44006060

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值