简体   繁体   中英

How to remove white lines when plotting multiple subplots in Matplotlib?

When I run the following code, even though running ax.axis('off') white lines appear.

plt.rcParams['figure.figsize'] = (6, 6)
fig=plt.figure()

for i in range(121):
    ax=plt.subplot(11,11,i+1)
    ax.axis('off')
    ax.imshow(weights[0][:,-i].reshape((28,28)),cmap='Spectral_r')
    ax.axis('off')
    plt.subplots_adjust(hspace = 0,wspace=0)

result:

subplots with white lines even when axis is set 'off'

The white lines are the background you see through at the spaces between the plots; it has nothing to do with the axes lines.

To make sure to have no space between the plots you can either let them be scaled automatically, imshow(..., aspect="auto") , or you set the subplot parameters such that there would not be any spaces left, eg in your case of a square figure with equal number of subplot rows and columns,

plt.subplots_adjust(left=0.15, right=0.85, bottom=0.15, top=0.85, hspace = 0, wspace=0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM