您的位置:首页 > 其它

pyplot.subplot 及 imshow绘图 去除坐标轴及调整子图间距

2017-07-21 23:03 295 查看
fnum = len(train_datasets)
plt.figure("show pickle", figsize=(10,10))
j = 0
for set_filename in train_datasets:
print('trying to read pickle: %s '  % set_filename)
try:
with open(set_filename, 'rb') as f:
dataset=pickle.load(f)
except Exception as e:
print('Unable to open pckle file ', set_filename, ':', e)
print ('%d images in total in file %s' % (len(dataset), set_filename))
for i in range(10):
plt.subplot( fnum, 10, 10*j + i + 1)
plt.imshow(dataset[i], cmap='gray');
##去除子图的坐标轴, 对上一个画出的子图起作用
plt.axis('off')
j += 1

##设定子图间距 , left < right, top > bottom, 数字表示窗口大小的比例(如下则子图间距为窗口大小的1%)
plt.subplots_adjust(left=0.04, top= 0.96, right = 0.96, bottom = 0.04, wspace = 0.01, hspace = 0.01)

关于为什么要了left<right (否则会报错 ValueError: bottom cannot be >= top):

When using 
subplots_adjust
,
the values of 
left
right
bottom
 and 
top
 are
to be provided as fractions of the figure width and height. In additions, all values are measured from the left and bottom edges of the figure. This is why 
right
 and 
top
 can't
be lower than 
left
 and 
right
.
A typical set-up is:  ----- 点击打开参考源
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: