matplotlib.pyplot.axis 画faster-rcnn的anchors

 

参考来源:https://matplotlib.org/api/_as_gen/matplotlib.pyplot.axis.html

心血来潮,想用matplotlib画一下faster-rcnn中生成的基础anchors,如下,

base_anchors = [[ -84.,-40., 99., 55.],
 [-176.,-88.,191.,103.],
 [-360. -184.,375.,199.],
 [ -56.,-56., 71., 71.],
 [-120. -120.,135.,135.],
 [-248. -248.,263.,263.],
 [ -36.,-80., 51., 95.],
 [ -80. -168., 95.,183.],
 [-168. -344.,183.,359.]]

本来觉得应该很简单,但是始终画不出来...坐标轴范围始终是0-1...

死磕之下终于攻破...主要是axis参数设置问题,这里简单讲解一下其使用方法,避免再入坑...

1. 调用方式

xmin, xmax, ymin, ymax = axis()
xmin, xmax, ymin, ymax = axis(xmin, xmax, ymin, ymax)
xmin, xmax, ymin, ymax = axis(option)
xmin, xmax, ymin, ymax = axis(**kwargs)
xmin, xmax, ymin, ymax = axis(str)

2. 参数

xmin, ymin, xmax, ymax 坐标轴的最大最小值
str‘on’

显示坐标轴

‘off’隐藏坐标轴
'equal'    调整坐标轴进行缩放
‘scaled’调整画布长宽进行缩放
'tight'设置坐标轴取值恰好满足数据取值范围
'auto'自动调整刻度
‘image’'scaled' with axis limits equal to data limits.(感觉和auto,tight差不多,不知道怎么翻译...)
'square'与scale类似,但要求xmax-xmin = ymax-ymin

3 代码及结果展示

# -*- coding:utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches

#a的每一行为一个anchor
#四个值分别为矩形对角线两顶点坐标
base_anchors = [[ -84.,-40., 99., 55.],
 [-176.,-88.,191.,103.],
 [-360. -184.,375.,199.],
 [ -56.,-56., 71., 71.],
 [-120. -120.,135.,135.],
 [-248. -248.,263.,263.],
 [ -36.,-80., 51., 95.],
 [ -80. -168., 95.,183.],
 [-168. -344.,183.,359.]]
fig = plt.figure() 
axes = fig.add_subplot(111) 

for i in range(9):
	p = a[i]
	rec = patches.Rectangle((p[0], p[1]),p[2]-p[0], p[3]-p[1], fill=False, linewidth=1, edgecolor='r', facecolor='none')
	axes.add_patch(rec)

#axes.axis('equal')
#axes.axis('scaled')
#axes.axis('tight')
#axes.axis('auto')
#plt.title('Base anchors')
'''
plt.xlim、plt.ylim 设置横纵坐标轴范围 
plt.xlabel、plt.ylabel 设置坐标轴名称 
plt.xticks、plt.yticks设置坐标轴刻度
'''
#plt.xlim(-600, 600)
#plt.ylim(-600, 600)

plt.show()

 str参数效果(不设置时,坐标轴始终为0-1.0),从左到右边分别为equal,scaled, tight, auto

上图scaled参数的效果明显与其它三种不同,它会自动将画布缩放为正方形。

equal和scaled区别在改变窗口大小时候区别更加明显,如下。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值