使用python matplotlib.pyplot画矩形框

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分别表明矩形框的长度和宽度spa

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

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

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

相关文章
相关标签/搜索