使用python matplotlib.pyplot画矩形框

2021-07-07 23:05

阅读:678

标签:pow   new   设置   get   axis   pytho   plt   mes   图表   

import matplotlib.patches as patches
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111) 

# 画矩形框
currentAxis = plt.gca()  # 获取当前子图
x_rect = x_index*Tr/480
y_rect = (y_index-fft_2pow_point/2)*fr/fft_2pow_point
rect = patches.Rectangle((x_rect, y_rect), target_height*Tr/480, target_weight*fr/fft_2pow_point, linewidth=2, edgecolor=r, facecolor=none)
currentAxis.add_patch(rect)

当前的图表和子图可以使用plt.gcf()和plt.gca()获得,

在Rectangle函数中 (x_rect, y_rect)代表矩形框的起始点(矩形框的左下角点),target_height*Tr/480, target_weight*fr/fft_2pow_point分别代表矩形框的长度和宽度

对于这四个参数,需要与已知的坐标轴坐标所对应,即已知我的横纵坐标为:

y_grid, x_grid = np.meshgrid(np.linspace(-fr / 2, fr / 2, width + 1),
                                         np.linspace(0, Tr, 480 + 1, endpoint=False))

facecolor这个参数对应的为:设置矩形框内部的参数。

使用python matplotlib.pyplot画矩形框

标签:pow   new   设置   get   axis   pytho   plt   mes   图表   

原文地址:https://www.cnblogs.com/yoyoyooo/p/9586042.html


评论


亲,登录后才可以留言!