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

来源:互联网 发布:mac做app开发 编辑:程序博客网 时间:2024/06/05 16:23
fnum = len(train_datasets)plt.figure("show pickle", figsize=(10,10))j = 0for 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 leftrightbottom 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:  ----- 点击打开参考源



原创粉丝点击