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()得到,函數
對於這四個參數,須要與已知的座標軸座標所對應,即已知個人橫縱座標爲: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